pandas python数据帧写入R数据格式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43046688/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 03:17:07  来源:igfitidea点击:

python dataframe write to R data format

pythonrpandasdataframe

提问by xiangjian Wu

I have a question with writing a dataframe format to R.

我有一个关于将数据帧格式写入 R 的问题。

I have 1000 column X 77 row data. I want to write this dataframe to R data.

我有 1000 列 X 77 行数据。我想将此数据帧写入 R 数据。

When I use function of

当我使用的功能

r_dataframe = com.convert_to_r_dataframe(df)

it gives me an error like dataframe object has no arttribute type.

它给了我一个错误,比如数据帧对象没有艺术属性类型。

When I see the code of com.convert_to_r_dataframe(). it just get the column of dataframe, and get the colunm.dtype.type. In this moment, the column is dataframe, I think large columns dataframe has inside dataframes? Any one have some idea to solve this problem?

当我看到 com.convert_to_r_dataframe() 的代码时。它只是获取数据框的列,并获取 colunm.dtype.type。此时,列是数据框,我认为大列数据框有内部数据框?任何人有一些想法来解决这个问题?

回答by takje

The data.frame transfer from Python to R could be accomplished with the feather format. Via this linkyou can find more information.

从 Python 到 R 的 data.frame 传输可以使用羽毛格式完成。通过此链接,您可以找到更多信息。

Quick example.

快速示例。

Export in Python:

在 Python 中导出:

import feather
path = 'my_data.feather'
feather.write_dataframe(df, path)

Import in R:

在 R 中导入:

library(feather)
path <- "my_data.feather"
df <- read_feather(path)

In this case you'll have the data in R as a data.frame. You can then decide to write it to an RData file.

在这种情况下,您会将 R 中的数据作为 data.frame。然后您可以决定将其写入 RData 文件。

save(df, file = 'my_data.RData')

回答by ??????

simplest, bestest practical solution is to export in csv

最简单、最实用的解决方案是导出 csv

import pandas as pd

dataframe.to_csv('mypath/file.csv')

and then read in R using read.csv

然后使用 R 读取 read.csv