python - 没有索引在列中 - 不能做单线箱线图
问题描述
到目前为止:
我加载了一个 csv 文件,没有标题。我输入了新的列名。
我剥离所有空间
我整理数据。R150全部出现。但我不能为我的Istwert列做箱线图。错误:
“[Index([',Istwert'], dtype='object')] 中没有一个在 [columns] 中”
如果我保存 csv,我没有发现任何可疑之处。
有任何想法吗?
到目前为止的代码:
import matplotlib as mpl
import matplotlib.pyplot as plt
import pandas as pd
df = pd.read_csv("<FILELOCATION>", delimiter=";" , skiprows = 1, names=["BID","Testschritt","Testbeschreibung","Sollwert","Minimum","Maximum","Istwert","Einheit"])
df = df.apply(lambda x: x.str.strip() if (x.dtype == "object") | (x.dtype == "float") else x)
result = df.loc[df["Testschritt"] == "R150"]
result.boxplot(column = ["Istwert"])
解决方案
始终以文本而不是图像的形式提供您的数据。OCR 很痛苦。
这对我有用。
- 你用的是什么版本的熊猫?
- 你的数据类型是什么?
result = pd.DataFrame(
{'idx': [226, 1070, 1914, 2758, 3602, 4446, 5290, 6134, 6978, 7822],
'BID': [7249, 7326, 7327, 7328, 7329, 7330, 7331, 7332, 7333, 7333],
'Testschritt': ['R150','R150', 'R150', 'R150', 'R150', 'R150', 'R150', 'R150', 'R150', 'R150'],
'Testbeschreibung': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
'Sollwert': [22, 22, 22, 22, 22, 22, 22, 22, 22, 22],
'Minimum': [19.8, 19.8, 19.8, 19.8, 19.8, 19.8, 19.8, 19.8, 19.8, 19.8],
'Maximum': [24.2, 24.2, 24.2, 24.2, 24.2, 24.2, 24.2, 24.2, 24.2, 24.2],
'Istwert': [20953, 21002, 20838, 20827, 20879, 20942, 20999, 20855, 20969, 20874],
'Einheit': ['KOhm', 'KOhm', 'KOhm', 'KOhm', 'KOhm', 'KOhm', 'KOhm', 'KOhm', 'KOhm', 'KOhm']}
).set_index("idx")
print(f"pandas: {pd.__version__}\n{result.dtypes}")
result.boxplot(column = ["Istwert"])
输出
pandas: 1.1.0
BID int64
Testschritt object
Testbeschreibung int64
Sollwert int64
Minimum float64
Maximum float64
Istwert int64
Einheit object
dtype: object
推荐阅读
- node.js - 如何在此路由路径中获取此帖子参数 ID?
- spring - 支持多种日期格式的 Kafka JsonDeserializer
- sas - Sas如何在显示器中有2个byvar
- c - 与“for循环”输出混淆
- java - 如何与 bin、conf 等少数目录一起构建战争
- javascript - 无法在 Angular 中访问对象属性
- r - 在 Rscript 中使用从 ShinyApp 获取的变量
- sql-server - Azure 数据同步可以用作主到主数据库复制吗?
- php - 我的前端不会与我的 Heroku 后端交互
- python - guvectorize 在 nopython 模式下不解析类型