-1

要转换为分钟的第一个表:

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

确实尝试过这样的:

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

但是对于 1629,049,我得到 16:29 必须是 27 分钟和 9 秒

4

1 回答 1

0

第一个解决方案是对所有行使用 apply 函数:

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

第二种解决方案(可能对 pandas C 实现更优化):

df["Time_Min"] = df["Time_Sec"].floordiv(60).map(str) + ":" + df["Time_Sec"].mod(60).map(str)
于 2021-05-10T20:02:20.153 回答