python - 如何使用 Python 将 Json 行转换为镶木地板?
问题描述
我需要用 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”:“ArrowInvalid”,
解决方案
如果您使用的是 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
以下是链接
推荐阅读
- java - 不需要新变量声明的小函数的可读性
- spring-security - SSHA512 加密并与 spring 5 匹配
- c# - 使用 UniformGrid 在 ListView 中嵌套绑定和布局
- azure - 使用 API v2 从 azure CR 获取单个层 blob
- python - sci-kit 学习 TransformerMixin 有奇怪的 fit_transform 行为
- google-cloud-platform - 仅在 apache 数据流中的同一管道中执行上一步后才执行某些步骤
- linux - 我们可以在使用 tc(traffic control) 时检查数据包统计信息吗?
- c# - 如何在一个用户控件中有两个滚动视图?
- python-3.x - Rasa 按钮在 Slack 中显示为文本
- docker - 无法使用 docker 登录到 canister.io - 授权服务器在响应中未包含令牌