Georg Heiler Georg Heiler - 1 year ago 93
Python Question

How to get data from R to pandas

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

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

%Rpull x
does not return the nice representation but rather a
. How can I convert it into something nicer e.g. a dict / pd.Dataframe? So far I had no luck following
pull from R


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

Answer Source

Just slice the ListVector:

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


If you want a dictionary instead:

dict([[i,j[0]] for i,j in enumerate(x)])
{0: 'first', 1: 'first'}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download