gpt4 book ai didi

python - Pandas 列对象分桶值提取

转载 作者:太空宇宙 更新时间:2023-11-04 09:53:53 24 4
gpt4 key购买 nike

在 Pandas 数据框中,我有一列的值如下:[2017-06-13 00:00:00, 2017-06-14 00:00:00)。有没有快速提取第一个日期2017-06-13 00:00:00的方法?

谢谢!

编辑:字符串末尾的括号不是拼写错误。

最佳答案

df.loc[0,'Column1'][0]
Out[85]: 'x'

示例数据

df = pd.DataFrame({'Column1':[['x','y'], ['a','b']],
'Out1':[1, 2]})

如果需要拉出整列

df.Column1.apply(pd.Series)[0]
Out[88]:
0 x
1 a
Name: 0, dtype: object

编辑,不是打字错误......

df.Column1.str.split(',',expand=True)[0].str[1:]

Out[97]:
0 2017-06-13 00:00:00
Name: 0, dtype: object

数据输入

df = pd.DataFrame({'Column1':['[2017-06-13 00:00:00, 2017-06-14 00:00:00)']})

关于python - Pandas 列对象分桶值提取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46716526/

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