简体   繁体   English

AttributeError:__enter__与read_parquet一起使用with语句时

[英]AttributeError: __enter__ while using with statement with read_parquet

I want to open all parquet files existing in a specific folder and draw a scatter plot with it. 我想打开特定文件夹中存在的所有镶木地板文件,并使用它绘制散点图。 I used following code: 我使用以下代码:

for file in glob.glob("*.parquet"):
    with pd.read_parquet(file, columns=["cordx", "cordy"]) as df:
        make some scaterplot

Files can be found as I let python print the file sucessfully. 我可以让python成功打印文件,因此可以找到file But i recive AttributeError: __enter__ . 但是我AttributeError: __enter__ And read_parquet is the corredct way to open those files. read_parquet是打开这些文件的正确方法。 When I dont use columns=[ ] I get pyarrow.lib.ArrowIOError: Arrow error: Out of memory: malloc of size 9771487328 failed error because the files are very big. 当我不使用column = []时,我得到pyarrow.lib.ArrowIOError: Arrow error: Out of memory: malloc of size 9771487328 failed因为文件很大。 So its necessary to load only those columns. 因此仅加载那些列是必要的。

This error tells you that pandas.read_parquet does not have a context manager implemented which means that you cannot call it using with because __enter__ and __exit__ methods are missing. 该错误告诉您pandas.read_parquet没有实现上下文管理器,这意味着您无法使用with调用with因为__enter____exit__方法。 Look in here How to read a Parquet file into Pandas DataFrame? 在这里查看如何将Parquet文件读入Pandas DataFrame?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM