using pandas 使用 if 条件生成 csv 文件

穆罕默德·沙里克

我有像start_time,end_timetime_taken在几分钟内的我只想time_taken等于 10 分钟时生成一个包含完整数据的 csv 文件

我目前的代码是:

if ( df['time_taken']) == 10:
  df.to_csv(r'result.csv')

它给出了如下错误:

The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
等离子体

您可以在保存之前对数据帧进行子集化,从而只保存符合您条件的数据帧部分:

df.loc[df.time_taken == 10].to_csv("results.csv")

你可能想继续阅读 .loc

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章