drop是一种方法,您使用调用它
[],因此它为您提供了:
'method' object is not subscriptable
更改为
()(正常方法调用),它应该可以工作:
import pandas as pddf = pd.Dataframe({"col_1": (0.0, 0.0, 1.0, 1.0, 0.0, 1.0, 1.0), "col_2": (0.0, 0.24, 1.0, 0.0, 0.22, 3.11, 0.0), "col_3": ("Mon", "Tue", "Thu", "Fri", "Mon", "Tue", "Thu")})df_new = df.drop(df[(df['col_1'] == 1.0) & (df['col_2'] == 0.0)].index)print(df_new)输出量
col_1 col_2 col_30 0.0 0.00 Mon1 0.0 0.24 Tue2 1.0 1.00 Thu4 0.0 0.22 Mon5 1.0 3.11 Tue



