简体   繁体   中英

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?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM