dataFrame重复提取行

问题描述 投票:1回答:1

下面的代码给出了以下Jupyter输出:

日期高开低收盘量

0 29/04/1992 2.21 2.21 1.98 1.99 0

1 29/04/1992 2.21 2.21 1.98 1.98 0

2 30/04/1992 2.02 2.32 1.95 1.98 0

大小:6686

没有重复?假


日期高开低收盘量

0 29/04/1992 2.21 2.21 1.98 1.99 0

1 29/04/1992 2.21 2.21 1.98 1.98 0

2 30/04/1992 2.02 2.32 1.95 1.98 0

没有重复?假

大小:6686

我应该在复制提取行中改变什么?

谢谢! fskilnik

checking = pd.DataFrame(df)

print(checking.head(3))

size2 = len(checking.index)
print('size:',size2)

print('no duplicates?', checking.date.is_unique)

checking.drop_duplicates(['date'], keep='last')

print(checking.head(3))

print('no duplicates?', checking.date.is_unique)

size2 = len(checking.index)
print('size:',size2)
python pandas
1个回答
1
投票

你应该将inplace=True添加到drop_duplicates方法或reassign dataframe像:

checking.drop_duplicates(['date'], keep='last', inplace=True)

要么:

checking = checking.drop_duplicates(['date'], keep='last')
© www.soinside.com 2019 - 2024. All rights reserved.