将 ParquetFile 转换为 Pandas Dataframe,其中包含一个在 python 中包含一组字符串的列

Rey*_*neh 0 python pandas fastparquet

我有一个镶木地板文件,它有一个包含几列的简单文件架构。我使用下面的代码将其读入python

from fastparquet import ParquetFile
pf = ParquetFile('inout_files.parquet')
Run Code Online (Sandbox Code Playgroud)

这运行良好,但是当我使用下面的代码将其转换为 pandas 时,出现以下错误:

df = pf.to_pandas()
Run Code Online (Sandbox Code Playgroud)

错误是:

 NotImplementedError: Encoding 4
Run Code Online (Sandbox Code Playgroud)

为了找到错误的来源,我分别df=pf.to_pandas(columns=col_to_retrieve)添加了列,并注意到错误是从具有字符串列表(例如(“a”、“b”、“c”))作为每个单元格值的列之一引发的列。

您知道如何将它转换为 Pandas 吗?知道有类型为 set(string) 的列吗?

Rin*_*orm 5

重新阅读这个问题后,我担心我的答案可能是非 sequitor ......

我有一个非常大的数据帧/镶木地板的相关问题,并收到错误:“BinaryArray 不能包含超过 2147483646 个字节”。

只要我没有类别类型,fastparquet似乎可以毫无错误地读取我的大表,而 pyarrow 可以毫无问题地编写它们。所以这是我目前的解决方法,直到这个问题得到解决:

0)取没有类别列的数据框并制作表格:

import pyarrow as pa    
table = pa.Table.from_pandas(df)
Run Code Online (Sandbox Code Playgroud)

1) 使用 pyarrow.parquet 写我的表:

 import pyarrow.parquet as pq
 pq.write_table(table, 'example.parquet')
Run Code Online (Sandbox Code Playgroud)

2) 使用 fastparquet 读取我的表:

from fastparquet import ParquetFile 
pf = ParquetFile('example.parquet')
Run Code Online (Sandbox Code Playgroud)

3)使用fastparquet转换为pandas:

df = pf.to_pandas()