简体   繁体   中英

multi query a dataframe table

I have a dataframe as follows:

student_id gender major admitted
35377 female Chemistry False
56105 male Physics True

etc.

How do I find the admission rate for females?

I have tried:

df.loc[(df['gender'] == "female") & (df['admitted'] == "True")].sum() 

But this returns an error:

TypeError: invalid type comparison

I guess the last column is Boolean. can you try this

df[df['gender'] == "F"]['admitted'].sum()

Remove that .loc and use this code: df[(df['gender'] == "female") & (df['admitted'] == "True")].sum()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM