简体   繁体   中英

Extract rows based on a condition - Pandas

I want to extract all rows from a df where the 'route_id' = 6A.

This is what I have tried but it returns a syntax error:

 df.loc(df['route_id'] = 6A)

Any tips? Thanks in advance.

Looks like you've used the assignment = instead of equality test == . The .loc needs square brackets and I also added some quotes around the '6A'

df.loc[df['route_id'] == '6A']

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