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

标签 python json pandas parquet

我需要用 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/

相关文章:

Python 3+ 在函数调用中导入包?

python - 不和谐重写和YouTube搜索出现问题

python - 单独模块中的 Flask View

python - 在 Python 中将字符串转换为枚举

基于 Java 的 JSON 操作

javascript - 处理稀疏数组的 JSON 实现

python - 将 Python 列表转换为多列 Pandas Dataframe

python - 如何使用 np.where 使用先前的行创建新列?

json - 如何让 JSON.NET 将日期/时间序列化为 ISO 8601?

python - 列表 append 在 Pandas 单元格中