Access multiple items with not equal to, !=

后端 未结 2 514
小蘑菇
小蘑菇 2021-01-30 12:04

I have the following Pandas DataFrame object df. It is a train schedule listing the date of departure, scheduled time of departure, and train company.



        
2条回答
  •  有刺的猬
    2021-01-30 12:35

    df[~df['Train'].isin(['DeutscheBahn', 'SNCF'])]
    

    isin returns the values in df['Train'] that are in the given list, and the ~ at the beginning is essentially a not operator.

    Another working but longer syntax would be:

    df[(df['Train'] != 'DeutscheBahn') & (df['Train'] != 'SNCF')]
    

提交回复
热议问题