wen
wen

Reputation: 193

'Series' object has no attribute 'to_datetime'

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!

Upvotes: 19

Views: 57176

Answers (2)

Espanta
Espanta

Reputation: 1140

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)

Upvotes: 25

U13-Forward
U13-Forward

Reputation: 71580

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.

Upvotes: 14

Related Questions