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

I have a huge data framework and I index it like this:

df.ix[<integer>]

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

Like me:

1) Stop Pandas from converting and save it as a data block?

OR

2) is it easy to convert the resulting series back to a data frame?

pd.DataFrame(df.ix[<integer>]) does not work because it does not preserve the original columns. It treats <integer> as a column, and columns as indices. Very grateful.

+5
source share
1 answer

You can do df.ix[[n]] to get a single-line frame of line string n .

+8
source

Source: https://habr.com/ru/post/1234936/


All Articles