0) &(flight_data_finalcopy["WeatherDelay"]>0)但似乎你需要ix来通过掩码选择UniqueCarrier和AirlineID列 – 有点修改boolean indexing:mask = (flight_dat..._python 筛选不是的多个条件">
当前位置:   article > 正文

python 多个条件筛选_从Python中的Dataframe过滤多个条件

python 筛选不是的多个条件

你需要()而不是[]:

arrival_delayed_weather = (flight_data_finalcopy["ArrDelay"] > 0) &

(flight_data_finalcopy["WeatherDelay"]>0)

但似乎你需要ix来通过掩码选择UniqueCarrier和AirlineID列 – 有点修改boolean indexing:

mask = (flight_data_finalcopy["ArrDelay"] > 0) &

(flight_data_finalcopy["WeatherDelay"]>0)

arrival_delayed_weather_filter=flight_data_finalcopy.ix[mask, ["UniqueCarrier","AirlineID"]]

样品:

flight_data_finalcopy = pd.DataFrame({'ArrDelay':[0,2,3],

'WeatherDelay':[0,0,6],

'UniqueCarrier':['s','a','w'],

'AirlineID':[1515,3546,5456]})

print (flight_data_finalcopy)

AirlineID ArrDelay UniqueCarrier WeatherDelay

0 1515 0 s 0

1 3546 2 a 0

2 5456 3 w 6

mask = (flight_data_finalcopy["ArrDelay"] > 0) & (flight_data_finalcopy["WeatherDelay"]>0)

print (mask)

0 False

1 False

2 True

dtype: bool

arrival_delayed_weather_filter=flight_data_finalcopy.ix[mask, ["UniqueCarrier","AirlineID"]]

print (arrival_delayed_weather_filter)

UniqueCarrier AirlineID

2 w 5456

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/600986
推荐阅读
相关标签
  

闽ICP备14008679号