Skip to content

Latest commit

 

History

History
33 lines (24 loc) · 674 Bytes

187.md

File metadata and controls

33 lines (24 loc) · 674 Bytes
@author jackzhenguo
@desc
@tag
@version 
@date 2020/03/25

第187个小例子:split 求时分(HH:mm)的分钟差

split 是更加高效的实现,同样需要先转化为 str 类型:

df['a'] = df['a'].astype(str)
df['b'] = df['b'].astype(str)

其次 split:

df['asplit'] = df['a'].str.split(':')
df['bsplit'] = df['b'].str.split(':')

使用 apply 操作每个元素,转化为分钟数:

df['amins'] = df['asplit'].apply(lambda x: int(x[0])*60 + int(x[1]))
df['bmins'] = df['bsplit'].apply(lambda x: int(x[0])*60 + int(x[1]))
[上一个例子](186.md) [下一个例子](188.md)