首页 > 解决方案 > 在 python pandas 中,如何使用 where 条件使用外连接?

问题描述

表格1

S.No  BusNo Timings People
1     1234  3:05 pm  55
2     3456  3:30 pm  45
3     8945  3:45 pm  50

Table 2 
BusNo  Model
1234   Leyland
3456   Viking

使用 pandas 加入此表的条件:busno model people count for people between 50 and 55 and group by model

预期输出:

表3

S.No BusNo Timings People Model
1    1234  3:05 pm  55    Leyland
3    8945  3:45 pm  50    Nan    

标签: python-3.xpandas

解决方案


我认为你需要pd.mergepd.Series.between

 df=pd.merge(df1,df2,on='BusNo',how='outer')
 df.loc[df['People'].between(50,55,inclusive=True),:]

推荐阅读