pandas 删除或选取需要某值的行

示例:

过滤某列含有 '层' 的行

#删除/选取某列含有特定数值的行

df1=df1[df1['A'].isin([1])]

df1[df1['A'].isin([1])]   # 选取df1中A列包含数字1的行

df1=df1[~df1['A'].isin([1])]  # 通过~取反,选取不包含数字1的行

或:

>>> bool = df.str.contains('Mr\.')
>>> filter_data = df[bool]

即可!

猜你喜欢

转载自www.cnblogs.com/yu121/p/12963272.html