0

我正在尝试从满足以下条件的数据框中删除行:

如果 x 介于 -1 和 1 之间,则删除该行,如果不是,则继续循环遍历数据帧。

这是针对 python 2.7 的,虽然我没有收到任何语法错误,但当我尝试在数据帧中的特定列上调用函数时,我的输出文件无法识别嵌入到函数中的条件。我很新,所以这里可能会出现多个问题。

def drop(row):
    counter = 0
    for row in df:
        if row in range(-1,1):
            df.drop(row, axis = 0)
        else:
            continue
        counter =+ 1 

df['column'].apply(drop)

4

1 回答 1

2

你只需要:

df.loc[~df['col'].isin(range(-1,1))]
于 2019-08-12T19:53:38.440 回答