【发布时间】:2021-06-26 10:59:01
【问题描述】:
我有巨大的 csv,我尝试使用 with open 过滤数据。
我知道我可以在命令行上使用 FINDSTR,但我想使用 python 创建一个过滤的新文件,或者我想创建一个 pandas 数据框作为输出。
这是我的代码:
outfile = open('my_file2.csv', 'a')
with open('my_file1.csv', 'r') as f:
for lines in f:
if '31/10/2018' in lines:
print(lines)
outfile.write(lines)
问题是生成的输出文件是=输入文件,没有过滤器(和文件大小一样)
谢谢大家
【问题讨论】:
-
接近一个错字:你只需要缩进
outfile.write(lines)和print(lines)一样。
标签: python pandas csv bigdata data-warehouse