python - Python:pd.read_csv(..., index_col='year') 后出现“标签不在列中”错误
问题描述
我正在尝试访问我的数据框中的列,但是它不起作用
import pandas as pd
df = pd.read_csv(data, index_col='year')
dfyear = df.loc[:,'year']
我收到以下错误:
KeyError: 'the label [year] is not in the [columns]'
我该如何解决?
解决方案
我认为year
是你的索引。尝试dfyear = df.index
代替dfyear = df.loc[:,'year']
推荐阅读
- php - 使用 PHP 解析 RSS Feed XML -> 无法获取 iTunes:image 属性
- azure - az login 从 github 操作任务失败
- kubernetes - 是否存在与 Openshift/Kubernetes 中的“限制”不同的“初始内存分配”?
- jasper-reports - Jaspersoft Reports,如何在 IF-ELSE 子句中检查文件是否存在?
- c# - 冒泡排序二维字符串数组
- java - 请求收到 MultipartFile 时的 MultipartException 和 IOFileUploadException
- mxnet - mxnet 模型转换为 onnx 成功但 ort.InferenceSession(model) 失败
- git - 提取自某个日期以来在 repo 中更改的所有文件
- java - 安排每 x 毫秒运行一次的任务
- android - 更改Android通知颜色的正确方法是什么?