I have a python dictionary in this format.
d = {1: {1, 2, 3},
2: {4, 5}}
I want to convert it into a pandas dataframe in this format.
Expected Output:
Source Target
1 1
1 2
1 3
2 4
2 5
I have tried doing this using list comprehension
d = {1: {1, 2, 3}, 2: {4, 5}}
df=pd.DataFrame([[key,v] for key, value in d.items() for v in value], columns=["Source", "Target"])
print(df)
But, is there any better way of doing this?