0

I am having dataframe containing time column to be like this:

time
2001-11-28 13:42:46 -0500
2001-10-10 22:14:00 -0400

I know how to convert them into time period but I fail to understand what does -0500 and -4000 even means.

This data I am using is an open source data for bugs related thing. If any one can help me with this it will be very helpful to me.

ninjakx
  • 35
  • 13

2 Answers2

1

There is timezone offset, you can processing different ways:

#convert to datetimes with different timezones
df['time1'] = pd.to_datetime(df['time'])
       
#convert to datetimes with utc tiemzone
df['time2'] = pd.to_datetime(df['time'], utc=True)

#remove timezone information
df['time3'] = pd.to_datetime(df['time'].str.rsplit(' -', n=1).str[0])
print (df)
                        time                      time1  \
0  2001-11-28 13:42:46 -0500  2001-11-28 13:42:46-05:00   
1  2001-10-10 22:14:00 -0400  2001-10-10 22:14:00-04:00   

                      time2               time3  
0 2001-11-28 18:42:46+00:00 2001-11-28 13:42:46  
1 2001-10-11 02:14:00+00:00 2001-10-10 22:14:00  
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
1

-0500 means five hours (05) and zero minutes (00) behind (-) UTC. For example New York City sometimes observes this time offset (specifically in winter, when DST is not in effect).

Read more about how UTC offsets work here: https://en.wikipedia.org/wiki/UTC_offset

And more on how Pandas handles times and time zones here (search for "timezone"): https://pandas.pydata.org/pandas-docs/stable/user_guide/timeseries.html

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • Got it so there is a universal time (GMT) and this offset tells us about how it differs from the universal time right? So I need to add this offset. I can't just simply remove it. – ninjakx Apr 06 '21 at 10:15
  • @ninjakx UTC and GMT are two different things – Panagiotis Kanavos Apr 06 '21 at 10:15
  • When you see a time like "13:42:46 -0500" it means "the time is 13 hours, 42 minutes and 46 seconds after local midnight in a time zone 5 hours behind UTC." So in UTC it is 18:42:46. If you want to display the local time, just remove the offset suffix. If you want to convert to UTC, subtract the UTC offset. – John Zwinck Apr 06 '21 at 10:16
  • Have to study about the UTC, GMT, DST. Thank you for providing me the explanation. – ninjakx Apr 06 '21 at 10:18
  • 1
    Most people do not care about the difference between UTC and GMT, but if you do: https://stackoverflow.com/questions/48942916/difference-between-utc-and-gmt/48960297 – John Zwinck Apr 06 '21 at 10:20