How to extract rows from python whith therse R-code

I have an object (call it X) with multiple tables, and each table contains rows and columns. So it is a 3 dimension object. So if I want to extract second rows from all the table, I can type
X[2,,]
So how can I do the same thing from python?

Hi Taylor,

Can you please give us a sample of the data?
You can use this guide:

r
#this must be a list
#In r we subset dataframes/tables with df[x,y]
#We subset list of dataframes with ls[[i]]...[x,y]
#ls[[1]] selects the first element of the list
#for example you have a list of list dataframes, you subset it with ls[[i]][[j]][x,y]
#A simple answer to your problem is to loop each element in the list and do whatever you want
new_df <- data.frame()
for(i in seq_along(ls)) {
 df[i] <- ls[[i]][2,]
}

#apply is faster, but its not easy to read for me

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.