One - One Code All

Blog Content

pandas中Series转换为DataFrame

Python 统计学-科学计算   2014-06-06 21:00:27

说明

虽然Series有一个to_frame()方法,但是当Series的index也需要转变为DataFrame的一列时,这个方法转换会有一点问题。所以,下面我采用将Series对象转换为list对象,然后将list对象转换为DataFrame对象。


实例

这里的month为一个series对象:


type(month)

pandas.core.series.Series


它的index为月份,values为数量,下面将这两列都转换为DataFrame的columns。


import pandas as pd


dict_month = {'month':month.index,'numbers':month.values}

df_month = pd.DataFrame(dict_month)



上一篇:pandas.DataFrame通过取反删除或选取含有特定数值的行或列
下一篇:airflow.cfg配置参数简介

The minute you think of giving up, think of the reason why you held on so long.