KeyError Traceback (most recent call last) /tmp/ipykernel_223/1273718879.py in <module> 47 48 # 每个特征取值的平均数 ---> 49 mean_data=data.groupby('花卉种类').mean() 50 plt.plot(mean_data.T, marker="o") 51 plt.xticks(rotation=0) /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/pandas/core/frame.py in groupby(self, by, axis, level, as_index, sort, group_keys, squeeze, observed, dropna) 6523 squeeze=squeeze, 6524 observed=observed, -> 6525 dropna=dropna, 6526 ) 6527 /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/pandas/core/groupby/groupby.py in __init__(self, obj, keys, axis, level, grouper, exclusions, selection, as_index, sort, group_keys, squeeze, observed, mutated, dropna) 531 observed=observed, 532 mutated=self.mutated, --> 533 dropna=self.dropna, 534 ) 535 /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/pandas/core/groupby/grouper.py in get_grouper(obj, key, axis, level, sort, observed, mutated, validate, dropna) 784 in_axis, name, level, gpr = False, None, gpr, None 785 else: --> 786 raise KeyError(gpr) 787 elif isinstance(gpr, Grouper) and gpr.key is not None: 788 # Add key to exclusions KeyError: '花卉种类'
时间: 2024-02-06 19:03:27 浏览: 135
linux 下 pip3 报错“ File “/usr/bin/pip3”, line 9, in from pip import mainImportError: canno”处理
5星 · 资源好评率100%
这是一个 KeyError,通常表示在 Python 字典或 Pandas 数据框中,你试图使用不存在的键来获取对应的值,导致了这个错误。在你的代码中,错误出现在对 '花卉种类' 这个键进行了分组操作,但是这个键在数据框中不存在。你需要检查一下数据框中是否有这个键,或者是是否写错了键的名字。如果你能提供更多的上下文和代码,我可以帮助你更好地找到解决方法。
阅读全文