Greem666
Greem666

Reputation: 949

Pandas - conversion to datetime

I have this small issue, where I first concatenate 3 columns in a DataFrame ['Year', 'Month', 'Day'] into a single column called ['Date'], and then I apply to this column datetime conversion, but afterwards when I check this column with .info() method, it still contains objects, not datetime objects: Failed Datetime conversion

DataFrame I am operating on is the first item in 'output' list, hence the address I apply before .info() method.

Any ideas why it does not obey me?

Upvotes: 0

Views: 620

Answers (1)

Scott Boston
Scott Boston

Reputation: 153540

You need to assign it back to dataframe['Date']. pd.to_datetime is not an inplace operation it returns back the Series with dtype datetime64.

dataframe['Date'] = pd.to_datetime(dataframe['Date'], format='%Y-%m-%d')

Upvotes: 2

Related Questions