简体   繁体   English

将Pandas数据框转换为Pandas系列

[英]Converting pandas dataframe to pandas series

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: 进入一个看起来与数据框完全一样的熊猫系列,但没有列名timestamp和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! 提前非常感谢您!

IIUC, use: IIUC,用途:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM