2

I would like to remove the +00:00 from the timestamp below. I used the code below to remove the T and Z from the timestamp but the dtype is still datetime64[ns, UTC] and ideally I would like to convert it to datetime64[ns]

df['Timestamp_column'].dt.tz_localize(None)

Timestamp_column before transformation:

2020-07-10T14:12:39.000Z    

Output:

2020-07-10 14:12:39+00:00   
FObersteiner
  • 22,500
  • 8
  • 42
  • 72
user12625679
  • 676
  • 8
  • 23
  • Does this answer your question? [How to remove T and Z in time in Python](https://stackoverflow.com/questions/51462050/how-to-remove-t-and-z-in-time-in-python) – Pygirl Jul 29 '20 at 07:03
  • I came across that one but didn't solve my problem – user12625679 Jul 29 '20 at 07:07

2 Answers2

6

you could tz_convert to None:

import pandas as pd

df = pd.DataFrame({'Timestamp_column': ['2020-07-10T14:12:39.000Z']})

df['Timestamp_column'] = pd.to_datetime(df['Timestamp_column']).dt.tz_convert(None)

# df['Timestamp_column']
# 0   2020-07-10 14:12:39
# Name: Timestamp_column, dtype: datetime64[ns]
FObersteiner
  • 22,500
  • 8
  • 42
  • 72
0
In [50]: df
Out[50]:
                       date
0  2020-07-10T14:12:39.000Z

In [51]: df.dtypes
Out[51]:
date    object
dtype: object

In [52]: df["new_date"] = pd.to_datetime(df["date"], format="%Y-%m-%dT%H:%M:%S.%fZ")

In [53]: df
Out[53]:
                       date            new_date
0  2020-07-10T14:12:39.000Z 2020-07-10 14:12:39

In [54]: df.dtypes
Out[54]:
date                object
new_date    datetime64[ns]
dtype: object
bigbounty
  • 16,526
  • 5
  • 37
  • 65