【问题标题】:why does it keep saying "During handling of the above exception, another exception occurred:" [duplicate]为什么它一直说“在处理上述异常期间,发生了另一个异常:” [重复]
【发布时间】:2019-12-29 07:23:18
【问题描述】:

我正在尝试从列中提取数据,但它一直在说还有另一个异常。

任何帮助将不胜感激

data = pd.read_csv('2019_data.csv')
data.head()


    Player Name Date    Statistic   Variable    Value
0   Cameron Champ   2019-08-18  Driving Distance    Driving Distance - (ROUNDS) 78
1   Rory McIlroy    2019-08-18  Driving Distance    Driving Distance - (ROUNDS) 68
2   Luke List   2019-08-18  Driving Distance    Driving Distance - (ROUNDS) 66
3   Wyndham Clark   2019-08-18  Driving Distance    Driving Distance - (ROUNDS) 87
4   Dustin Johnson  2019-08-18  Driving Distance    Driving Distance - (ROUNDS) 69


df = data.groupby(['Player Name']).first()

ds = df.sort_values(by = ["Value"])

ds["Player Name"]

但它说

KeyError: 'Player Name'

During handling of the above exception, another exception occurred:

【问题讨论】:

  • 因为你的 pandas 代码中的异常被引发到 python 核心,而 python 引发了另一个异常。

标签: python pandas


【解决方案1】:

Pandas 不喜欢列名中的空格。看看这个答案:

https://stackoverflow.com/a/30514678/1688590

【讨论】:

  • 如果您认为它已经在另一个问题中得到回答,您可以将其标记为重复吗?
  • 在您发表评论之前,我已经将其标记为重复,但作为 Tatsuya 的新贡献者,仅用标记“回答”可能会感到不礼貌。
猜你喜欢
  • 2019-09-25
  • 2018-08-01
  • 1970-01-01
  • 2021-11-08
  • 2019-08-20
  • 1970-01-01
  • 1970-01-01
  • 2019-03-14
相关资源
最近更新 更多