我正在尝试将一列str类型转换为datetime类型。但是当我编写代码时:

df.timeStamp = df.timeStamp.to_datetime

它只是告诉我
AttributeError: 'Series' object has no attribute 'to_datetime'

但是当我尝试
pd.to_datetime(df.timeStamp)

有用。

我是python的新手,希望有人可以解释为什么会发生这种情况。

感谢您的宝贵时间!

最佳答案

因为to_datetime只是pandas模块的有效属性,仅此而已。

所以这就是为什么:
AttributeError: 'Series' object has no attribute 'to_datetime'
(请参见突出显示的部分)

因此,当然不能以这种方式使用to_datetime

关于python - “系列”对象没有属性 'to_datetime',我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54318395/

10-10 21:14
查看更多