gpt4 book ai didi

python - 如何使用Python将Json线转换为 Parquet ?

转载 作者:行者123 更新时间:2023-12-01 06:55:56 24 4
gpt4 key购买 nike

我需要用 Python 以一种简单的方式来完成它。我正在尝试使用 Pandas,但我才刚刚开始,这对我来说非常困难。

现在我正在尝试使用 json2parquet:

try:
input_filename= '/tmp/source_file'
source_file = s3.get_object(Bucket="myBucket", Key="myJsonLinesFile")
datajson = source_file['Body'].read()
with open(input_filename, 'wb') as f:
f.write(datajson)
convert_json(input_filename, '/tmp/final.parquet')


except Exception as e:
print(e)
raise e

但我收到以下错误: "errorMessage": "不能混合列表和非列表、非空值", "errorType": "箭头无效",

最佳答案

如果您使用的是 pandas 0.25.3 版本,您可以安装 fastparquet 或 pyarrow 库并执行以下代码

>>> df = pd.DataFrame(data={'col1': [1, 2], 'col2': [3, 4]})
>>> df.to_parquet('df.parquet.gzip',
... compression='gzip') # doctest: +SKIP

更多详细信息可以在这里找到 - https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.to_parquet.html

下面是链接

  1. 快速 Parquet - https://pypi.org/project/fastparquet/
  2. pyarrow - https://arrow.apache.org/docs/python/install.html#using-pip

关于python - 如何使用Python将Json线转换为 Parquet ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58805974/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com