我想将 csv 作为 Parquet 文件上传到 S3 存储桶。下面是代码片段。
df = pd.read_csv('right_csv.csv')
csv_buffer = BytesIO()
df.to_parquet(csv_buffer, compression='gzip', engine='fastparquet')
csv_buffer.seek(0)
上面给我一个错误:TypeError: expected str, bytes or os.PathLike object, not _io.BytesIO
如何让它发挥作用?
最佳答案
根据 documentation ,当使用fastparquet
作为引擎时,不能使用io.BytesIO
。必须使用 auto
或 pyarrow
引擎。引用文档。
The engine fastparquet does not accept file-like objects.
下面的代码没有任何问题。
import io
f = io.BytesIO()
df.to_parquet(f, compression='gzip', engine='pyarrow')
f.seek(0)
关于pandas - 使用 Pandas 将 csv 转换为 Parquet 文件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70860399/