我在将 Feather 对象读入 R 时遇到错误,该对象是从 python session 中取出的。
在 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 信息:
R
R version 3.3.1 (2016-06-21) Platform: x86_64-apple-darwin13.4.0 (64-bit) Running under: OS X 10.10.5 (Yosemite)
locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
attached base packages: [1] stats graphics grDevices utils
datasets methods baseother attached packages: [1] feather_0.3.0
loaded via a namespace (and not attached): [1] assertthat_0.1 hms_0.2 tools_3.3.1 tibble_1.2 Rcpp_0.12.5
python
'2.7.10 (default, Jul 3 2015, 12:05:53) \n[GCC 4.2.1 Compatible Apple LLVM 6.1.0 (clang-602.0.53)]'
Pandas version: '0.20.3'
Numpy version: '1.13.1'
最佳答案
问题很简单,字符串列中的值应该是 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/