python - dataFrame重复提取行
问题描述
下面的代码给出了以下 Jupyter 输出:
日期开高低收盘量
0 1992 年 4 月 29 日 2.21 2.21 1.98 1.99 0
1 1992 年 4 月 29 日 2.21 2.21 1.98 1.98 0
2 1992 年 4 月 30 日 2.02 2.32 1.95 1.98 0
尺寸:6686
没有重复?错误的
日期开高低收盘量
0 1992 年 4 月 29 日 2.21 2.21 1.98 1.99 0
1 1992 年 4 月 29 日 2.21 2.21 1.98 1.98 0
2 1992 年 4 月 30 日 2.02 2.32 1.95 1.98 0
没有重复?错误的
尺寸:6686
我应该在重复提取行中更改什么?
谢谢!弗斯基尔尼克
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)
解决方案
您应该添加inplace=True
到drop_duplicates
方法等reassign
:dataframe
checking.drop_duplicates(['date'], keep='last', inplace=True)
或者:
checking = checking.drop_duplicates(['date'], keep='last')
推荐阅读
- c - 我无法在 C 中操作位域
- powerbi - 带有最后值的 3 个月滚动平均值
- spring-batch - 在 AsyncItemProcessor 中设置上下文参数
- ios - 应用程序进入后台后,AVAudioPlayer 停止返回正确的 currentTime
- php - “getimagesize(): SSL operation failed with code 1” 仅在本地 Xampp
- scala - 如何在结构化流中创建列的所有值的列表?
- eclipse - 我的 JUnit 测试使用 Java 11 中的 maven build 执行,但无法通过 RunIT->Run As->Units 运行相同的 Junit 测试,它总是说 not JUnits found
- spring-integration - 使用 Spring 从 pubsub 消费一批消息
- python - Python脚本监控点击事件但阻止它们,不允许点击事件通过
- python - 如何使用python解析表?