将 Feather 对象读入从 Python session 中输出的 R 时遇到错误。
在 python 中:
In [248]: import pandas as pd
In [249]: pd.DataFrame({'col': ['a','b','c']}).to_feather('strings_df.feather')
在 R 中:
> library(feather)
> df = read_feather('strings_df.feather')
Error in coldataFeather(x, i) :
RAW() can only be applied to a 'raw', not a 'list'
这与字符串作为对象存储在
pandas.Series
中的事实有关吗?对这里发生的事情有什么想法吗?session 信息:
电阻
Python
最佳答案
问题很简单,字符串列中的值应该是 unicode
类型,而不是 str
。以下按预期工作:
pd.DataFrame({'col': [u'a',u'b',u'c']}).to_feather('strings_df.feather')
关于python 到 R 与字符串的 Feather 兼容性,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45311790/