kamome
kamome

Reputation: 858

How do I change time format in pandas?

I am trying to change the format of a column (serie) in pandas.

The column is datetime object in the following format: 2017-06-14 08:00:00

I would like to format the column as: 2017-06-14T08:00Z. Including T as separator and Z as UTC time

df["time(UTC)"].dt.strftime("%Y:%m%:%dT%H:%MZ")`

But is doesn't work.

How can I do that?

Upvotes: 1

Views: 13087

Answers (1)

jezrael
jezrael

Reputation: 862481

I think you need change format only:

df=pd.DataFrame({'time(UTC)':pd.to_datetime(['2017-06-14 08:00:00','2017-06-14 08:00:00'])})

df['new'] = df["time(UTC)"].dt.strftime("%Y-%m-%dT%H:%MZ")
print (df)
            time(UTC)                new
0 2017-06-14 08:00:00  2017-06-14T08:00Z
1 2017-06-14 08:00:00  2017-06-14T08:00Z

Upvotes: 3

Related Questions