仅对于某些列,如何删除下一个pandas dataframe行等于上一行时
我已经使用此代码创建了一个名为df
的数据帧:
# initialize list of lists
data = {'ID': [1,2,3,4,5,6,7],
'feature1': [100,32,100,100,100,93,100],
'feature2': [100,32,100,100,100,93,100],
'feature3': [100,32,100,100,100,93,100],
}
# Create DataFrame
df = pd.DataFrame(data)
数据框架看起来像这样:
print(df)
ID feature1 feature2 feature3
0 1 100 100 100
1 2 32 32 32
2 3 100 100 100
3 4 100 100 100
4 5 100 100 100
5 6 93 93 93
6 7 100 100 100
我想删除列的值:
farture1
和< /strong>feature2
和feature3
与以前的行完全相同。在上面的示例中,我需要删除行3
和4
,以便所得的数据帧看起来像这样:
I have created a dataframe called df
with this code:
# initialize list of lists
data = {'ID': [1,2,3,4,5,6,7],
'feature1': [100,32,100,100,100,93,100],
'feature2': [100,32,100,100,100,93,100],
'feature3': [100,32,100,100,100,93,100],
}
# Create DataFrame
df = pd.DataFrame(data)
The dataframe looks like this:
print(df)
ID feature1 feature2 feature3
0 1 100 100 100
1 2 32 32 32
2 3 100 100 100
3 4 100 100 100
4 5 100 100 100
5 6 93 93 93
6 7 100 100 100
I want to remove the rows in which the values of columns:
feature1
andfeature2
andfeature3
are exactly the same as the previous row. In the example above, I need to remove rows3
and4
, so that the resulting dataframe will look like this:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
filter
功能
类似列,然后计算上一个和当前行之间的差异,并检查差异是否为0
for All功能
代码>列Filter
thefeature
like columns then calculate difference between previous and current row and check whether the difference is0
for all thefeature
columns