pandas timestamp series to string? pandas timestamp series to string? arrays arrays

pandas timestamp series to string?


Consider the dataframe df

df = pd.DataFrame(dict(timestamp=pd.to_datetime(['2000-01-01'])))df   timestamp0 2000-01-01

Use the datetime accessor dt to access the strftime method. You can pass a format string to strftime and it will return a formatted string. When used with the dt accessor you will get a series of strings.

df.timestamp.dt.strftime('%Y-%m-%d')0    2000-01-01Name: timestamp, dtype: object

Visit strftime.org for a handy set of format strings.


Use astype

>>> import pandas as pd>>> df = pd.to_datetime(pd.Series(['Jul 31, 2009', '2010-01-10', None])) >>> df.astype(str)0    2009-07-311    2010-01-102           NaTdtype: object

returns an array of strings


Following on from VinceP's answer, to convert a datetime Series in-place do the following:

df['Column_name']=df['Column_name'].astype(str)