,python,matplotlib,plot"/>

首页 > 解决方案 > 键错误:

问题描述

这是我的代码的一部分(大部分都被省略了):

我该如何解决或解决这个问题?

KeyError: 'Loss ($M)' 图形大小 720x432 与 0 轴

该错误消息甚至意味着什么?我是 Python 新手,所以请用任何人都能理解的非常基本的术语来解释它。

对于我的库,我正在使用: import matplotlib from matplotlib import pyplot as plt

plt.figure(figsize = (10, 6))
plt.hist(df["Loss ($M)"], bins = 25, color = c, normed = True)
plt.xlabel("Incurred Loss ($M)", fontsize = 12)
plt.ylabel("N", fontsize = 12)
plt.title("Loss Severity Distribution", fontsize = 14)

KeyError: 'Loss ($M)' Figure size 720x432 with 0 Axes>

标签: pythonmatplotlibplot

解决方案


KeyError: 'Loss ($M)' Figure size 720x432 with 0 Axes>

这些实际上是两个完全独立的消息。第一个也是重要的一个是

KeyError: 'Loss ($M)'

"Loss ($M)"这意味着您的 dataframe中没有命名列df

第二个只是一个后果。这甚至不是错误,只是您创建的图形的字符串表示形式。显然,它报告了没有轴的图形,因为应该绘制某些东西的命令由于关键错误而失败。


推荐阅读