【发布时间】:2020-09-08 20:44:01
【问题描述】:
我有一个 csv 文件,其中包含我想提取到新列的字段中的文本块。例如,我的 csv 如下所示:
house, paint, status-text
house1, green, this house is nice it gets a status of result: PASS this is good
house2, red, this house is not too nice it gets a status of result: FAIL this is bad
house3, blue, this house is the best it gets a status of result: PASS this is great,
我想运行一个简单的正则表达式将 (result: PASS) 或 (result: FAIL) 提取到一个新列中,因此 CSV 现在如下所示:
house, paint, status-text, status
house1, green, this house is nice it gets a status of result: PASS this is good, PASS
house2, red, this house is not too nice it gets a status of result: FAIL this is bad, FAIL
house3, blue, this house is the best it gets a status of result: PASS this is great, PASS
我正在考虑使用 Pandas 数据框,但不确定如何解析 (PASS/FAIL) 并将其移动到 3 行的自己的列中,并且可能会扩展到数百行。任何关于如何作为小样本执行此操作的示例将不胜感激。
【问题讨论】:
标签: python-3.x pandas csv parsing