python - 键错误:
问题描述
这是我的代码的一部分(大部分都被省略了):
我该如何解决或解决这个问题?
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>
解决方案
KeyError: 'Loss ($M)' Figure size 720x432 with 0 Axes>
这些实际上是两个完全独立的消息。第一个也是重要的一个是
KeyError: 'Loss ($M)'
"Loss ($M)"
这意味着您的 dataframe中没有命名列df
。
第二个只是一个后果。这甚至不是错误,只是您创建的图形的字符串表示形式。显然,它报告了没有轴的图形,因为应该绘制某些东西的命令由于关键错误而失败。
推荐阅读
- google-cloud-firestore - Firestore - 遍历 50k 文档是个好主意。它会足够快吗?
- c# - 检查对象是否为 Byte[]
- jquery - 从带有起始值的复选框中求和和减去价格
- node.js - Cordova-Electron:有没有办法添加 preload.js 脚本并禁用节点集成?
- flutter - 为flutter构建ios-framework设置最低iOS操作系统版本
- php - 在 CodeIgniter 中上传图像和文件时出错
- azure-data-factory - Azure 数据工厂 (ADF V2) 清除或删除旧的/不需要的管道活动运行
- excel - 带有 Sharepoint 文件的 Powershell BindToMoniker 不起作用
- python-3.x - 将kivy图像转换为PIL图像
- css - 列不占满高度