xiangjian Wu
xiangjian Wu

Reputation: 116

python dataframe write to R data format

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

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

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?

Upvotes: 8

Views: 11667

Answers (2)

takje
takje

Reputation: 2800

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

Quick example.

Export in Python:

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

Import in 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.

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

Upvotes: 11

ℕʘʘḆḽḘ
ℕʘʘḆḽḘ

Reputation: 19395

simplest, bestest practical solution is to export in csv

import pandas as pd

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

and then read in R using read.csv

Upvotes: 4

Related Questions