将Pandas数据保存为parquet文件

7
我将尝试使用以下代码将pandas对象保存为parquet格式:
LABL = datetime.now().strftime("%Y%m%d_%H%M%S")
df.to_parquet("/data/TargetData_Raw_{}.parquet".format(LABL))

这让我产生了错误:

ArrowTypeError: ("Expected bytes, got a 'float' object", 'Conversion failed for column Pre-Rumour_Date with type object')

pandas的数据类型如下:

0
Announced_Date                  object
Completed_Date                  object
Pre-Rumour_Date                 object
                                object
Lapsed_Date                     object
Target_Company                  object
Bidder_Company                  object
Seller_Company                  object
Deal_Value_USD(_m)              object
Exit_Type                       object
Buy_Type                        object
Sell_Stake_(%)                  object
Buy_Stake_(%)                   object
Months_Held                     object
Private_Equity_House            object
ADATE                   datetime64[ns]
dtype: object

1
@AnuragDabas,然后显示错误TypeError:Object of type 'int64' is not JSON serializable - delalma
2
尝试使用 Series.astype() 将您的“object”列转换为显式类型。 - gshpychka
2
我认为你可能需要将最后一列的类型从日期时间转换为字符串,使得数据帧具有相同的类型,这是将其转换为Parquet格式的条件。 - user16310106
3
你可以阅读这个链接 https://github.com/pandas-dev/pandas/issues/21228#issuecomment-462590774 - user16310106
3
好的,这是需要翻译的内容:This as well, https://github.com/equinor/webviz-config/issues/285 - user16310106
1个回答

4
尝试使用以下代码: df.astype(str).to_parquet("/data/TargetData_Raw_{}.parquet".format(LABL)) 将数据框转换为字符串并保存为Parquet文件。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接