![](/img/trans.png)
[英]Pandas Create new column based on a count and a condition from another dataframe
[英]Create new column based on condition from one column and the value from another column in pandas
您可以创建映射dict
d = {'h' : 60*60, 'min' : 60, 'ms' : 1/1000}
df['seconds'] = df['time_unit'].map(d) * df['time']
seconds = []
for i,r in df.iterrows():
if r['time_unit'] == 'h':
seconds.append(r['time']*3600)
elif r['time_unit'] == 'min':
seconds.append(r['time']*60)
elif r['time_unit'] == 'ms':
seconds.append(r['time']/1000)
df['seconds'] = seconds
我想这会奏效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.