Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get data from R to pandas

In a jupiter notebook I created some 2-d-list in R like

%%R
first <- "first"
second <- "second"

names(first) <- "first_thing"
names(second) <- "second_thing"

x <- list()
index <- length(x)+1
x[[index]] = first
x[[index +1]] = second

a %Rpull x does not return the nice representation but rather a ListVector. How can I convert it into something nicer e.g. a dict / pd.Dataframe? So far I had no luck following http://pandas.pydata.org/pandas-docs/stable/r_interface.html pull from R

edit

The list I want to convert is a 2-d list like results the updated code snipped from above

like image 720
Georg Heiler Avatar asked Nov 25 '25 08:11

Georg Heiler


1 Answers

Just slice the ListVector:

%Rpull x
pd.DataFrame(data=[i[0] for i in x], columns=['X'])

Image

If you want a dictionary instead:

dict([[i,j[0]] for i,j in enumerate(x)])
{0: 'first', 1: 'first'}
like image 134
Nickil Maveli Avatar answered Nov 27 '25 21:11

Nickil Maveli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!