Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pandas df.describe() , is it possible to do it by row without transposing?

Tags:

python

pandas

Pandas df.describe() is a very useful method to have an overview of your df. However, it describes by columns and I would like to have an overview of the rows instead. Is there any way to make it work "by_row" without transposing the df?

like image 995
alec_djinn Avatar asked Dec 04 '15 09:12

alec_djinn


People also ask

Which pandas function is used to apply to DF describe () to transpose the table?

We can also use the transpose() method or . T in order to get a transposed version of our dataframe. The output will look something like this (for the first ten rows). If you want to see each columns' name, number of rows, null-value, and data type, use the info() function.

What does pandas describe () method return?

Pandas DataFrame describe() Method The describe() method returns description of the data in the DataFrame. If the DataFrame contains numerical data, the description contains these information for each column: count - The number of not-empty values.

How do I transpose specific rows in pandas?

Pandas DataFrame. transpose() is a library function that transpose index and columns. The transpose reflects the DataFrame over its main diagonal by writing rows as columns and vice-versa. Use the T attribute or the transpose() method to swap (= transpose) the rows and columns of DataFrame.

What are the descriptive stats provided by the describe () function?

The describe() function computes a summary of statistics pertaining to the DataFrame columns. This function gives the mean, std and IQR values. And, function excludes the character columns and given summary about numeric columns.


1 Answers

Use apply and pass axis=1 to call describe row-wise:

In [274]:
df = pd.DataFrame(np.random.randn(4,5))
df

Out[274]:
          0         1         2         3         4
0  0.651863  0.738034 -0.477668 -0.561699  0.047500
1 -1.565093 -0.671551  0.537272 -0.956520  0.301156
2 -0.951549  2.177592  0.059961 -1.631530 -0.620173
3  0.277796  0.169365  1.657189  0.713522  1.649386

In [276]:
df.apply(pd.DataFrame.describe, axis=1)

Out[276]:
   count      mean       std       min       25%       50%       75%       max
0      5  0.079606  0.609069 -0.561699 -0.477668  0.047500  0.651863  0.738034
1      5 -0.470947  0.878326 -1.565093 -0.956520 -0.671551  0.301156  0.537272
2      5 -0.193140  1.458676 -1.631530 -0.951549 -0.620173  0.059961  2.177592
3      5  0.893451  0.722917  0.169365  0.277796  0.713522  1.649386  1.657189
like image 168
EdChum Avatar answered Oct 10 '22 05:10

EdChum