将列表理解与
times的提取属性一起使用:
import datetime as datetimedf = pd.Dataframe({'time': [datetime.time(9, 30, 38), datetime.time(13, 40, 27), datetime.time(18, 5, 24), datetime.time(4, 58, 8), datetime.time(9, 0, 9)]})print (df) time0 09:30:381 13:40:272 18:05:243 04:58:084 09:00:09df[['h','m','s']] = pd.Dataframe([(x.hour, x.minute, x.second) for x in df['time']])
或转换为
strings,拆分后转换为
int:
df[['h','m','s']] = df['time'].astype(str).str.split(':', expand=True).astype(int)print (df) time h m s0 09:30:38 9 30 381 13:40:27 13 40 272 18:05:24 18 5 243 04:58:08 4 58 84 09:00:09 9 0 9
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)