0

I have a Windows Event logs which are in an ElasticSearch cluster. I am using Pandas to query ES vis the API. The output for the datetime field is initially an "object". Using pandas.to_datetime I have successfully converted it to a Dtype of "datetime64[ns, UTC]".

However the data in the field in an undesired format of, yyyy-mm-dd hh:mm:ss+00:00.

I don't want the "+00:00" part. I have tried pandas.to_datetime with format to no avail. Here is how I am converting the object.

services["datetime"]=pd.to_datetime(services["datetime"])

Here is the field output, 2020-08-31 11:02:03+00:00 Here is the desired output, 08/31/2020 11:02:03

Not sure how to get there.

Berry
  • 31
  • 1
  • 3

2 Answers2

0

One more step:

services["datetime"] = pd.to_datetime(services["datetime"])
services["datetime"] = services["datetime"].dt.strftime("%m/%d/%Y %H:%M:%S")
  • Thanks. I found this to remove the timezone. `type_10_df["datetime"]=type_10_df["datetime"].dt.tz_localize(None)` – Berry Sep 24 '20 at 16:45
0

It's not nano-seconds, it's the time-zone. It's part of the date time in pandas, and +00:00 just means it on UTC time.

There are several options to eliminate time-zone awareness in pandas. Check out those questions:

How to remove timezone from a Timestamp column in a pandas dataframe

Strip timezone info in pandas

Convert pandas timezone-aware DateTimeIndex to naive timestamp, but in certain timezone

Roim
  • 2,986
  • 2
  • 10
  • 25
  • Thanks! I ended up using this... `type_10_df["datetime"]=pd.to_datetime(type_10_df["datetime"])` `type_10_df["datetime"]=type_10_df["datetime"].dt.tz_localize(None)` – Berry Sep 24 '20 at 16:40