Answer How to convert csv file data using Python_2

Asked 2 years ago, Updated 2 years ago, 70 views

I want to use datetime to specify all the columns in the 'date' column, convert them, and put them back in.

There's an error. Please give me a solution

python data csv datetime

2022-09-22 19:27

1 Answers

The error strptime() arguemnt 1 must be str, not Series appears that change_csv['Date'] is not a string, but Series.

I think you can take the string from Series and process it as shown below.

for index in change_csv['Date'].index:
    dateStr = change_csv['Date'][index]
    date = datetime.strptime(dateStr, '%b %d, %y')
    change_csv['Date'][index] = date.strftime('%Y-%m-%d')


2022-09-22 19:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.