python 与 R 的 Feather 与字符串的兼容性

标签 python r pandas feather

我在将 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 base

other 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/

相关文章:

r - r 中不包括 NA 的列长度

r - 在容器内生成 Shiny 进程时保留环境变量

python - Pandas:如何合并不同的数据框?

python - pandas:按二级索引范围对 MultiIndex 进行切片

r - 在 ggplot 中,如何创建带有尖边(如 "toothpicks")的线条可视化?

Python Pandas reshape 数据框

python - Django : How can I fix this when adding facebook login to django app using social-auth?

python - 从 pyside/opencv 访问网络摄像头

python - 如何为 Keras 实现 Beholder(Tensorboard 插件)?

python - 如何将 mapinfo 文件加载到 geopandas 中