pandas 筛选出某列中包含指定信息的行 pandas contains()

需求

剔除指定列中包含 “小计”信息的行。

解决

借助 pandas.DataFrame.filed.str.contains()

Step1:取出包含 “小计” 信息的行;

这样,剩下的数据就都是不包含 “小计” 的数据了;

df[df['deliveryPrice'].str.contains('小计')]

Step2:取反

基于Step1取反;

这样就拿到不包含 “小计” 的行;

df[~(df['deliveryPrice'].str.contains('小计'))]

Done.

原文地址:https://www.cnblogs.com/bigtreei/p/14661178.html