gpt4 book ai didi

python - 将 Pandas 数据框转换为 Pandas 系列

转载 作者:太空宇宙 更新时间:2023-11-04 00:00:54 25 4
gpt4 key购买 nike

我需要一些关于数据类型问题的帮助。我正在尝试转换 pandas 数据框,如下所示:

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

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

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

这应该不难,但由于我是 pandas 的初学者,我在想办法做到这一点时遇到了一些麻烦。

如果能在这个问题上得到一些帮助,那就太好了。

非常感谢您!

最佳答案

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

关于python - 将 Pandas 数据框转换为 Pandas 系列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55760594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com