Converting pandas dataframe to pandas series

天涯浪子 提交于 2021-02-10 12:37:24

问题


I need some help with a data types issue. I'm trying to convert a pandas dataframe, which looks like the following:

timestamp    number
2018-01-01     1
2018-02-01     0
2018-03-01     5
2018-04-01     0
2018-05-01     6

into a pandas series, which looks exactly like the dataframe, without the column names timestamp and number:

 2018-01-01     1
 2018-02-01     0
 2018-03-01     5
 2018-04-01     0
 2018-05-01     6

It shouldn't be difficult, but I'm having a little trouble figuring out the way to do it, as I'm a beginner in pandas.

It would be great to get some help with this issue.

Thank you very much in advance!


回答1:


IIUC, use:

df.set_index('timestamp')['number'].rename_axis(None)

2018-01-01    1
2018-02-01    0
2018-03-01    5
2018-04-01    0
2018-05-01    6


来源:https://stackoverflow.com/questions/55760594/converting-pandas-dataframe-to-pandas-series

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!