我想用同一帧的数据来转换熊猫。在
我发现的唯一方法是通过这个系列的to_dict
方法,这不是非常有效,因为它返回到纯python模式,而不是numpy/pandas/cython。在
你对更好的方法有什么建议吗?在
非常感谢。在
>>> import pandas as pd
>>> flagInfoSeries = pd.Series(({'a': 1, 'b': 2}, {'a': 10, 'b': 20}))
>>> flagInfoSeries
0 {'a': 1, 'b': 2}
1 {'a': 10, 'b': 20}
dtype: object
>>> pd.DataFrame(flagInfoSeries.to_dict()).T
a b
0 1 2
1 10 20
我想你可以理解:
计时:
^{pr2}$编辑:
如果需要保留索引,请尝试将
index=flagInfoSeries.index
添加到DataFrame
构造函数:计时:
样本:
这样可以避免}也可能很慢:
to_dict
,但是{编辑:我看到jezrael添加了计时比较。这是我的:
^{pr2}$相关问题 更多 >
编程相关推荐