Python 将包含不同长度列表的字典转换为2列数据帧
我有一本这样的字典Python 将包含不同长度列表的字典转换为2列数据帧,python,pandas,list,dataframe,dictionary,Python,Pandas,List,Dataframe,Dictionary,我有一本这样的字典 my_dict = {0:[1,2], 1:[1, 5, 100,120], 2:[1, 89, 90, 1625, 98, 0, 10]} 我想把它转换成一个只有两列的数据帧,就像这个一样 col1 col2 0 [1, 2] 1 [1, 5, 100,120] 2 [1, 89, 90, 1625, 98, 0, 10] 第二列包括数字列表。有什么建议吗 s=pd.Series(my_dict).reset_
my_dict = {0:[1,2],
1:[1, 5, 100,120],
2:[1, 89, 90, 1625, 98, 0, 10]}
我想把它转换成一个只有两列的数据帧,就像这个一样
col1 col2
0 [1, 2]
1 [1, 5, 100,120]
2 [1, 89, 90, 1625, 98, 0, 10]
第二列包括数字列表。有什么建议吗
s=pd.Series(my_dict).reset_index()
Out[32]:
index 0
0 0 [1, 2]
1 1 [1, 5, 100, 120]
2 2 [1, 89, 90, 1625, 98, 0, 10]
输出:
col1 col2
0 0 [1, 2]
1 1 [1, 5, 100, 120]
2 2 [1, 89, 90, 1625, 98, 0, 10]
col1 col2
0 0 [1, 2]
1 1 [1, 5, 100, 120]
2 2 [1, 89, 90, 1625, 98, 0, 10]