KonK3
KonK3

Reputation: 81

Pandas take only a cell from the describe function

I am using pandas describe function for the below result:

dt_d=dt.describe()
print(dt_d)

count     120.00000   120.000000    120.000000   120.000000
mean        5.89000     3.060000      3.795833     1.190833
std         0.84589     0.441807      1.792861     0.757372
min         4.30000     2.000000      1.000000     0.100000
25%         5.17500     2.800000      1.575000     0.300000
50%         5.80000     3.000000      4.450000     1.400000
75%         6.40000     3.325000      5.100000     1.800000
max         7.90000     4.400000      6.900000     2.500000

If I want to take a cell from the describe function, for example, from the mean row, the mean in the third column, how will I be able to call it on its own?

Upvotes: 0

Views: 639

Answers (1)

ALollz
ALollz

Reputation: 59579

df.describe() returns a DataFrame so you can just index it as you would any other DataFrame, using .loc.

import pandas as pd
import numpy as np
np.random.seed(123)
df = pd.DataFrame(np.random.randint(1,10,(10,3)))

df.describe()
#              0          1          2
#count  10.00000  10.000000  10.000000
#mean    4.30000   2.400000   5.400000
#std     2.58414   1.429841   2.458545
#min     1.00000   1.000000   1.000000
#25%     2.25000   1.000000   4.250000
#50%     4.00000   2.500000   6.000000
#75%     5.00000   3.000000   7.000000
#max     9.00000   5.000000   8.000000

df.describe().loc['mean', 2]
#5.4

Upvotes: 1

Related Questions