2

I've got a data set read from csv in pandas. It turns out that pandas drops the 0 - When the minute is single digit. when I do a .tail on the column this is what I get?

5196    15:58
5197    15:59
5198     16:0
5199     16:1
5200     16:2
5201     16:3

Is this just a pandas thing and I shouldn't worry about it? Is there a fix for displaying it properly?

Behrooz Karjoo
  • 4,250
  • 10
  • 38
  • 48

1 Answers1

3

You can make it an explicit timedelta rather than a string:

In [11]: df
Out[11]:
       time
5196  15:58
5197  15:59
5198   16:0
5199   16:1
5200   16:2
5201   16:3

In [12]: pd.to_timedelta(df.time + ":0")
Out[12]:
5196   15:58:00
5197   15:59:00
5198   16:00:00
5199   16:01:00
5200   16:02:00
5201   16:03:00
Name: time, dtype: timedelta64[ns]

In [13]: df["time"] = pd.to_timedelta(df.time + ":0")

In [14]: df
Out[14]:
         time
5196 15:58:00
5197 15:59:00
5198 16:00:00
5199 16:01:00
5200 16:02:00
5201 16:03:00
Andy Hayden
  • 359,921
  • 101
  • 625
  • 535