alz
alz

Reputation: 347

Pandas: Describing a single column while Masking

Code:

csv[csv["country"]=="US"].describe()

generates

>              points     price
>     count  10005.000   8633.000000
>     mean   88.566417   39.739836
>     std    2.666808    38.473267
>     min    80.000000   5.000000
>     25%    87.000000   18.000000
>     50%    88.000000   28.000000
>     75%    90.000000   50.000000
>     max    100.000000  595.000000

I want to generate the same info without the "price" column:

          points    
count   10005.000000    
mean    88.566417   
std     2.666808    
min     80.000000   
25%     87.000000   
50%     88.000000   
75%     90.000000   
max     100.000000

Should I combine the Boolean mask csv["country"]=="US" with this?

csv["points"].describe()

If yes, how can I do that?

Upvotes: 0

Views: 35

Answers (1)

Mykola Zotko
Mykola Zotko

Reputation: 17834

You can use:

csv.loc[csv["country"]=="US", 'points'].describe()

Upvotes: 1

Related Questions