Python 如何删除替换行
我有一个带有重复ID的熊猫数据帧。下面是我的数据框架Python 如何删除替换行,python,pandas,Python,Pandas,我有一个带有重复ID的熊猫数据帧。下面是我的数据框架 id nbr type count 7 21 High 4 7 21 Low 6 8 39 High 2 8 39 Low 3 9 13 High 5 9 13 Low 7 如何仅删除类型为Low的行您可以尝试以下方法: df = df[df.type != "Low"] 另一个可能的解
id nbr type count
7 21 High 4
7 21 Low 6
8 39 High 2
8 39 Low 3
9 13 High 5
9 13 Low 7
如何仅删除类型为Low
的行您可以尝试以下方法:
df = df[df.type != "Low"]
另一个可能的解决方案是使用 您还可以执行以下操作:
df.drop_duplicates('nbr', inplace=True)
这样,您就不必重新分配它。您也可以使用以下方法对df进行切片: 这将每2行执行一次
df.drop_duplicates('nbr', inplace=True)
df.iloc[::2]