如何过滤pandas数据框中所有不能被n整除的数据

Nab*_*zir 0 python numpy filter dataframe pandas

在这种情况下 n=100

这是我的数据集

id   amount
1    1000
2    2000
3    2300.7632
4    4560
Run Code Online (Sandbox Code Playgroud)

我想要的是

id   amount
3    2300.7632
4    4560
Run Code Online (Sandbox Code Playgroud)

jez*_*ael 5

boolean indexing与模一起使用%

df = df[df['amount'] % 100 != 0]
print (df)
   id     amount
2   3  2300.7632
3   4  4560.0000
Run Code Online (Sandbox Code Playgroud)

与...一样:

df = df[df['amount'].mod(100).ne(0)]
print (df)
   id     amount
2   3  2300.7632
3   4  4560.0000
Run Code Online (Sandbox Code Playgroud)

细节:

print (df['amount'].mod(100))
0     0.0000
1     0.0000
2     0.7632
3    60.0000
Name: amount, dtype: float64
Run Code Online (Sandbox Code Playgroud)

实际上,这个答案是在 pandas 中实现的。