[英]Pandas apply to large csv file
我有一个3GB的CSV文件,需要修改。 我有一列要应用lambda函数(应更改行的值)
到目前为止,我尝试过的解决方案是将CSV作为分块文件读取,但内存问题仍然发生
这是我到目前为止尝试过的:
dataframe = read_csv(file_path, iterator=True, chunksize=10000)
for chunk in dataframe:
chunk['column_name'].apply(change_row_lambda_function)
dataframe.to_csv(result_file_path, sep=',')
尝试这个:
# write header (column names)
read_csv(file_path, nrows=1).head(0).to_csv(result_file_path)
dataframe = read_csv(file_path, iterator=True, chunksize=10000)
for chunk in dataframe:
chunk['column_name'] = chunk['column_name'].apply(change_row_lambda_function)
chunk.to_csv(result_file_path, mode='a', header=None)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.