I am trying to convert one column str type to datetime type. But when I write the code:
df.timeStamp = df.timeStamp.to_datetime
it just tell me
AttributeError: 'Series' object has no attribute 'to_datetime'
But when I try
pd.to_datetime(df.timeStamp)
it works.
I am new to python and hope someone could explain why it happens.
I appreciate your time!
I am kind of late, but still useful for future readers.
Below code converts a column of type object in a pandas df to type timestamp
df.timeStamp = pd.to_datetime(df.timeStamp)
Because to_datetime
is only a valid attribute to pandas
module, that's all.
So that's why:
AttributeError: 'Series' object has no attribute 'to_datetime'
(see highlighted part)
So of course, to_datetime
can't be used that way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With