在python的pandas包中,其中一个数据类型DataFrame想要转换为Serie会自动转换,那将Series转为DataFrame又如何实现呢?本文介绍python中series转dataframe的两种方法:1、使用to_frame()后,再转置index与columns实现Series转换成DataFrame;2、先to_dict()转成字典再转为list再转dataframe。
方法一:使用to_frame()后,再转置index与columns实现Series转换成DataFrame
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
|
方法二:先to_dict()转成字典再转为list再转dataframe
1 2 3 4 5 |
|
以上就是python中series转dataframe的两种方法,希望能对你有所帮助哟·更多python学习推荐:python教程。