Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 235
xiangjian Wu Avatar asked Mar 27 '17 12:03

xiangjian Wu


People also ask

Is Feather better than pickle?

For data larger than 10^4, feather is the fastest. File size: pickle compressed format has the smallest file size. Feather, parquet, msgpack, pickle (uncompressed) are almost the same file file size. Pickle with compression is only ~10% smaller, but much slower read and write speed.

Is parquet better than pickle?

TLDR: On read speeds, PICKLE was 10x faster than CSV, MSGPACK was 4X faster, PARQUET was 2–3X faster, JSON/HDF about the same as CSV. On write speeds, PICKLE was 30x faster than CSV, MSGPACK and PARQUET were 10X faster, JSON/HDF about the same as CSV.

How do you assign data to a DataFrame in R?

We can create a dataframe in R by passing the variable a,b,c,d into the data. frame() function. We can R create dataframe and name the columns with name() and simply specify the name of the variables.

What is R data format?

rdata or . rda) is a format designed for use with R, a system for statistical computation and related graphics, for storing a complete R workspace or selected "objects" from a workspace in a form that can be loaded back by R.


2 Answers

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')
like image 90
takje Avatar answered Sep 21 '22 23:09

takje


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

like image 33
ℕʘʘḆḽḘ Avatar answered Sep 21 '22 23:09

ℕʘʘḆḽḘ