I have this dictionary:
data = {'key1': [2, 6, 7],
'key2': [9, 5, 3]}
How can I convert it into this pandas dataframe
key value
0 key1 2
1 key1 6
2 key1 7
3 key2 9
4 key2 5
5 key2 3
?
I tried:
import pandas as pd
data = {'key1': [2, 6, 7], 'key2': [9, 5, 3]}
df = pd.DataFrame(data.items())
print(df)
but it returns:
0 1
0 key1 [2, 6, 7]
1 key2 [9, 5, 3]
I also tried:
import pandas as pd
data = {'key1': [2, 6, 7], 'key2': [9, 5, 3]}
df = pd.DataFrame.from_dict(data)
print(df)
but it returns:
key1 key2
0 2 9
1 6 5
2 7 3