将 pandas 数据框转换为 pandas 系列 [英] Converting pandas dataframe to pandas series

查看:58
本文介绍了将 pandas 数据框转换为 pandas 系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一些有关数据类型问题的帮助.我正在尝试转换如下所示的 Pandas 数据框:

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

变成一个看起来与数据框完全一样的pandas系列,没有列名时间戳和数字:

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

这应该不难,但我在弄清楚如何做到这一点时有点困难,因为我是 Pandas 的初学者.

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.

在此先非常感谢您!

推荐答案

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

这篇关于将 pandas 数据框转换为 pandas 系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆