pandas: filter rows of DataFrame with operator chaining

前端 未结 14 2321
悲哀的现实
悲哀的现实 2020-11-22 16:46

Most operations in pandas can be accomplished with operator chaining (groupby, aggregate, apply, etc), but the only way I

14条回答
  •  一整个雨季
    2020-11-22 17:40

    pandas provides two alternatives to Wouter Overmeire's answer which do not require any overriding. One is .loc[.] with a callable, as in

    df_filtered = df.loc[lambda x: x['column'] == value]
    

    the other is .pipe(), as in

    df_filtered = df.pipe(lambda x: x['column'] == value)
    

提交回复
热议问题