我试图从数据框df
中删除前两行,并使用this post中建议的答案。但是,我得到了错误AttributeError: Cannot access callable attribute 'ix' of 'DataFrameGroupBy' objects, try using the 'apply' method
,并且不知道如何使用apply
方法来实现这一点。我已经展示了下面的相关代码行:
df = df.groupby('months_to_maturity')
df = df.ix[2:]
编辑:对不起,当我想删除前两行时,我应该说我想删除与每个months_to_maturity
值关联的前两行。在
谢谢你
这就是
tail(-2)
将要做的。但是,groupby.tail
不采用负值,因此需要调整:这将为您提供所需的数据帧,但它的索引现在是一个多索引。 如果您只想删除
^{pr2}$df
中的行,只需使用drop
,如下所示:相关问题 更多 >
编程相关推荐