Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to make 1 by n dataframe from series in pandas?

I have a huge dataframe, and I index it like so:

df.ix[<integer>]

Depending on the index, sometimes this will have only one row of values. Pandas automatically converts this to a Series, which, quite frankly, is annoying because I can't operate on it the same way I can a df.

How do I either:

1) Stop pandas from converting and keep it as a dataframe ?

OR

2) easily convert the resulting series back to a dataframe ?

pd.DataFrame(df.ix[<integer>]) does not work because it doesn't keep the original columns. It treats the <integer> as the column, and the columns as indices. Much appreciated.

like image 219
makansij Avatar asked Nov 01 '15 03:11

makansij


1 Answers

You can do df.ix[[n]] to get a one-row dataframe of row n.

like image 96
BrenBarn Avatar answered Nov 15 '22 02:11

BrenBarn