使用Python从文件中读取数据时出现问题(pandas.io.解析器.TextFileReader文件)

2024-04-25 06:23:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从带有pandas的文件中读取数据集,但是当我使用pd.read\U csv文件(),程序读取了它,但是当我想看到数据帧出现时:

pandas.io.解析器.TextFileReader位于0x1b3b6b3e198

作为附加信息,该文件太大(约9G)

该文件使用垂直线作为分隔符,我尝试使用chunksize,但不起作用。你知道吗

import pandas as pd
df = pd.read_csv(r"C:\Users\dguerr\Documents\files\Automotive\target_file", iterator=True, sep='|',chunksize=1000)

我想以传统的数据帧格式导入数据。你知道吗


Tags: 文件csv数据io程序信息解析器pandas
1条回答
网友
1楼 · 发布于 2024-04-25 06:23:51

您可以通过执行以下操作逐块加载它:

import pandas as pd

path_to_file = "C:/Users/dguerr/Documents/Acxiom files/Automotive/auto_model_target_file"
chunk_size = 1000
for chunk in pd.read_csv(path_to_file,chunksize=chunk_size):
     # do your stuff

相关问题 更多 >