Convert the following date strings into datetime objects: datelist = ['14-Sep-2017', '9-Sep-2017']. Note: Use the to_datetime method of pandas. Capture the result in the variable 'dates_to_be_searched' and print it.
This will generate a Dataframe with the strings and convert using the to_datetime
method:
dates_to_be_searched = ['14-Sep-2017', '9-Sep-2017']
df = pd.DataFrame({'Date': dates_to_be_searched})
df['Date'] = pd.to_datetime(df['Date'])
print(df)
Outputs:
Date
0 2017-09-14
1 2017-09-09
Here you go:
import pandas as pd
datelist = ['14-Sep-2017', '9-Sep-2017']
dates_to_be_searched = [pd.to_datetime(x) for x in datelist]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.