如何通过索引名称从 pandas.core.frame.DataFrame 中删除一行?

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

我有一个看起来像这样的数据框:

              GBPEUR
date                
2018-06-22  1.140732
2018-06-25  1.135847
2018-06-26  1.134301
1900-01-01       NaN

df.列:

Index(['GBPEUR'], dtype='object')

df.index:

Index([2018-06-22, 2018-06-25, 2018-06-26, 1900-01-01], dtype='object', name='date')

我正在尝试做:

df = df.drop(index='1900-01-01')

但是我遇到了:

KeyError: "['1900-01-01'] not found in axis"

我真的很困惑,

1900-01-01
不是在轴上吗?

pandas dataframe
1个回答
0
投票

尝试:

df.drop('1900-01-01', axis=0)

输出:

              GBPEUR
date                
2018-06-22  1.140732
2018-06-25  1.135847
2018-06-26  1.134301
© www.soinside.com 2019 - 2024. All rights reserved.