chevron_left
Time Series Cookbook
Adding new column containing the difference between two date columnsCombining columns containing date and timeCombining columns of years, months and daysConverting a column of strings to datetimeConverting dates to stringsConverting datetime column to date and time columnsConverting DatetimeIndex to Series of datetimeConverting index to datetimeConverting UNIX timestamp to datetimeCreating a column of datesCreating a range of datesExtracting month and year from Datetime columnGetting all weekdays between two datesGetting all weekends between two datesGetting day unit from date columnGetting month unit from date columnGetting name of months in date columnGetting week numbers from a date columnGetting day of week of date columnsGetting year unit from date columnModifying datesOffsetting datetimeRemoving time unit from datesSetting date to beginning of monthSorting DataFrame by datesUsing dates as the index of a DataFrame
0
0
0
new
Converting a DataFrame column of strings to datetime in Pandas
Programming
chevron_rightPython
chevron_rightPandas
chevron_rightCookbooks
chevron_rightDataFrame Cookbooks
chevron_rightTime Series Cookbook
schedule Jul 1, 2022
Last updated Python●Pandas
Tags tocTable of Contents
expand_more To convert a DataFrame column of strings to datetime
, use Pandas to_datetime(~)
method.
Example
Consider the following DataFrame:
df
A0 2020/12/251 2020/12/26
Here, column A
of type string. To convert the date strings to actual datetime
:
df.dtypes
A datetime64[ns]dtype: object
Note that pd.to_datetime(~)
is preferred over DataFrame.astype(~)
since the former has more parameters to customize how the dates are to be converted.
Published by Isshin Inada
Edited by 0 others
Did you find this page useful?
Ask a question or leave a feedback...
0
0
0
Enjoy our search