-1

the first table to be converted to minute:

Time_sec >>> Time_Min)
362.7313    00:06:02,7
490.669     00:08:10,7
824.5673    00:13:44,6
951.829     00:15:51,8
13.0447     00:00:13,0
13.0678     00:00:13,1
122.5468    00:02:02,5
536.7552    00:08:56,8
811.9501    00:13:32,0
938.1133    00:15:38,1
13809718    00:02:19,0
619.4331    00:10:19,4
1407.5125   00:23:27,5
16290049    00:27:09,0

did try like this:

df['Time_sec'] = pd.to_datetime(df['Time_sec'].datetime.timedelta(seconds =df['time_sec'])

but for 1629,049 i get 16:29 what must be 27min an 9sec

Quang Hoang
  • 146,074
  • 10
  • 56
  • 74
e33
  • 15
  • 4
  • I'm not sure I understand what you're looking for here. The conversions don't make sense, your question says nanoseconds to minutes, but you use `seconds=` in your coding attempt. You mention 1,620,049 should be 27:09, but the value in the your data is 16,290,049. – Henry Ecker May 10 '21 at 19:59
  • So my questions are: (1) are you trying to convert from seconds or nanoseconds? (2) How do you want to handle something like 16290049 which is over 180 days worth of seconds? – Henry Ecker May 10 '21 at 20:01

1 Answers1

0

A first solution would be to use the apply function to all rows :

df["Time_Min"] = df["Time_Sec"].apply(lambda x: f"{x // 60}:{x % 60}")

A second solution (maybe more optimized regarding pandas C implementation) :

df["Time_Min"] = df["Time_Sec"].floordiv(60).map(str) + ":" + df["Time_Sec"].mod(60).map(str)
AlexTorx
  • 753
  • 4
  • 9