问题描述
result = pa.array(col,type=type_,from_pandas=True,safe=safe)
File "pyarrow\array.pxi",line 265,in pyarrow.lib.array
File "pyarrow\array.pxi",line 80,in pyarrow.lib._ndarray_to_array
File "pyarrow\error.pxi",line 107,in pyarrow.lib.check_status
pyarrow.lib.ArrowTypeError: ('Expected a string or bytes dtype,got float64','Conversion Failed for column NOTES with type float64')
列类型为varchar,因此将其转换为str。但是该列的记录中有一些数字值,我怀疑数据帧会将它们解析为浮点型。因此,在转换为实木复合地板时,它会返回一个会产生错误的浮点值。
是否可以将这些记录的值转换为str格式。
我尝试使用astype(str),但没有用。
解决方法
是的,parquet 要求每列只有一种类型。要解决上述情况(即混合值类型),请将其转换为 Pandas 'string',如下所示:
df['NOTES'] = df['NOTES'].astype('string')
# & then ... df.to_parquet(...)