Ashish Choudhary
Ashish Choudhary

Reputation: 181

TypeError: strptime() argument 1 must be string, not Series

I am writing a single entry from a column of a data frame

2011100101 is interpreted as 1 AM of 1st October 2011.

I want it to change in the format as YYYY-Mmm-dd HH

train['date1']=datetime.strptime(train['ID'], '%Y%m%d%H')

but getting an error TypeError: strptime() argument 1 must be string, not Series

How to change in the required format for the entire entries in a single column?

Upvotes: 13

Views: 34465

Answers (1)

bouletta
bouletta

Reputation: 525

you can use the apply() method

train['date1'] = train['ID'].apply(lambda x: datetime.strptime(x, '%Y%m%d%H'))

Upvotes: 17

Related Questions