Python数据框如何根据索引条件删除某些行

2024-04-19 15:01:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个以日期为索引的每日价格数据框。如果索引日期为<;“2010/1/1”,我想删除所有行。我试过bars.drop(bars.index<'2010/7/17'== True)它引起了一个错误ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()。有什么想法吗?你知道吗

enter image description here


Tags: ofthe数据ltantrueindexvalue
1条回答
网友
1楼 · 发布于 2024-04-19 15:01:57

如果您真的想使用您的条件drop行,您可以执行以下操作:

bars.drop(bars.index[bars.index<'2010/1/1'])

但最好使用@EdChum solution和loc对数据帧进行切片。你知道吗

相关问题 更多 >