如果要删除Leading zeros,请使用lstrip()
df['Time'] = df['time_col'].astype('str').apply(lambda x: x.lstrip('0'))
#输出
time_col Time
0 02:10:41 2:10:41
1 09:19:22 9:19:22
2 10:55:46 10:55:46
3 30:64:50 30:64:50
如果要删除 Trailing zeros,请使用 rstrip()
df['Time'] = df['time_col'].astype('str').apply(lambda x: x.rstrip('0'))
#输出
0 02:10:41 02:10:41
1 09:19:22 09:19:22
2 10:55:46 10:55:46
3 30:64:50 30:64:5
您的情况...如果您想同时删除 Leading 和 trailing 使用 strip()
df['Time'] = df['time_col'].astype('str').apply(lambda x: x.strip('0'))
#输出
time_col Time
0 02:10:41 2:10:41
1 09:19:22 9:19:22
2 10:55:46 10:55:46
3 30:64:50 30:64:5