【发布时间】:2019-06-18 16:20:21
【问题描述】:
我同时使用 R 和 Python,我想将我的一个 pandas DataFrames 编写为羽毛,以便在 R 中更轻松地使用它。但是,当我尝试将其编写为羽毛时,我得到了以下错误:
ArrowInvalid: trying to convert NumPy type float64 but got float32
我仔细检查了我的列类型,它们已经是 float 64:
In[1]
df.dtypes
Out[1]
id Object
cluster int64
vector_x float64
vector_y float64
无论使用feather.write_dataframe(df, "path/df.feather") 或df.to_feather("path/df.feather"),我都会遇到相同的错误。
我在 GitHub 上看到了这个,但不明白它是否相关:https://issues.apache.org/jira/browse/ARROW-1345 和 https://github.com/apache/arrow/issues/1430
最后,我可以将其保存为 csv 并更改 R 中的列(或仅在 Python 中进行整个分析),但我希望使用它。
编辑 1:
尽管有以下很好的建议,但仍然遇到同样的问题,所以更新我尝试过的内容。
df[['vector_x', 'vector_y', 'cluster']] = df[['vector_x', 'vector_y', 'cluster']].astype(float)
df[['doc_id', 'text']] = df[['doc_id', 'text']].astype(str)
df[['doc_vector', 'doc_vectors_2d']] = df[['doc_vector', 'doc_vectors_2d']].astype(list)
df.dtypes
Out[1]:
doc_id object
text object
doc_vector object
cluster float64
doc_vectors_2d object
vector_x float64
vector_y float64
dtype: object
编辑 2:
经过大量搜索,问题似乎在于我的集群列是由 int64 整数组成的列表类型。所以我想真正的问题是,羽毛格式是否支持列表?
编辑 3:
为了把它打个结,feather 不支持像列表这样的嵌套数据类型,至少现在还不支持。
【问题讨论】:
-
将列表存储为字符串有效吗?
标签: python r pandas list feather