[英]python dataframe how to delete some rows based on index conditions
To say I had a daily price dataframe with the date as its index. 可以说我有一个以日期为索引的每日价格数据框。 and I'd like to delete all the rows if its index date <"2010/1/1" . 并且如果索引日期<“ 2010/1/1”我想删除所有行。 I tried bars.drop(bars.index<'2010/7/17'== True)
It raised an error ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
我尝试了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()
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
. ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
。 Any ideas? 有任何想法吗?
If you actually wants to drop
rows with your condition you could do following: 如果您确实想根据条件drop
行,则可以执行以下操作:
bars.drop(bars.index[bars.index<'2010/1/1'])
But it's better to slice dataframe using @EdChum solution with loc
. 但是最好使用带有loc
@EdChum解决方案对数据帧进行切片。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.