加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python与R兼容羽毛与字符串

发布时间:2020-12-20 13:18:49 所属栏目:Python 来源:网络整理
导读:我在将一个羽毛对象读入从 python会话中输出的R时遇到错误. 在python中: In [248]: import pandas as pdIn [249]: pd.DataFrame({'col': ['a','b','c']}).to_feather('strings_df.feather') 在R: library(feather) df = read_feather('strings_df.feather'
我在将一个羽毛对象读入从 python会话中输出的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中存储为对象的事实有关吗?关于这里发生了什么的任何想法?

会话信息:

[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')

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读