从数据框中的列中删除值

Removing values from a column in a dataframe

我正在尝试从数据框 (df2) 的 ProductType - type:int64 列中删除这些值:

df3 = df2.drop(df2.index[df2['ProductType'] == '100', '109', '110', '118', '123', '124', '143', '153', '163', 
                                        '173', '179', '190', '191', '196', '197', '200', '205', '206', 
                                        '208', '209', '211', '214', '215', '216', '219', '221', '222', 
                                        '223', '225', '226', '401', '999'], inplace = True) 

AttributeError: 只有整数、切片 (:)、省略号 (...)、numpy.newaxis (None) 和整数或布尔数组是有效的索引

我该如何解决这个问题?谢谢

试试这个

数据 = data.drop(columns="ProductType")

打印(数据)

我尝试了这个并且成功了:

df3 = df2.drop(df2[(df2['ProductType']== '100')|(df2['ProductType']== '109')|(df2['ProductType']== '110')].index)

你可以试试这个:

removed_lst = ['100', '109', '110', '118', '123', '124', '143', '153', '163', 
               '173', '179', '190', '191', '196', '197', '200', '205', '206', 
               '208', '209', '211', '214', '215', '216', '219', '221', '222', 
               '223', '225', '226', '401', '999']

df3 = df2[~df2["ProductType"].isin(removed_lst)]