pandas ValueError:无法解释参数的值

bvjveswy  于 2022-11-27  发布在  其他
关注(0)|答案(1)|浏览(597)

将“bmi.csv”加载到Dataframe中,并使用relplot()创建数据散点图,x轴为身高,y轴为体重,根据性别对图点进行着色,并根据BMI指数改变点的大小。
我的代码是:

import pandas as pd
import seaborn as sns
df = pd.read_csv('bmi.csv')

BMI = pd.DataFrame(df)
g = sns.relplot(x = 'Height', y = 'Weight', data=df);b

我得到:

Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    g = sns.relplot(x = 'Height', y = 'Weight', data=df);b
  File "/Users/aleksikurunsaari/Library/Python/3.10/lib/python/site-packages/seaborn/relational.py", line 862, in relplot
    p = plotter(
  File "/Users/aleksikurunsaari/Library/Python/3.10/lib/python/site-packages/seaborn/relational.py", line 538, in __init__
    super().__init__(data=data, variables=variables)
  File "/Users/aleksikurunsaari/Library/Python/3.10/lib/python/site-packages/seaborn/_oldcore.py", line 640, in __init__
    self.assign_variables(data, variables)
  File "/Users/aleksikurunsaari/Library/Python/3.10/lib/python/site-packages/seaborn/_oldcore.py", line 701, in assign_variables
    plot_data, variables = self._assign_variables_longform(
  File "/Users/aleksikurunsaari/Library/Python/3.10/lib/python/site-packages/seaborn/_oldcore.py", line 938, in _assign_variables_longform
    raise ValueError(err)
ValueError: Could not interpret value `Height` for parameter `x`
6vl6ewon

6vl6ewon1#

除了这个错误,为什么你要从一个 Dataframe 构造一个 Dataframe ,而且你没有使用它?我在这里讨论的是BMI

df = pd.read_csv('bmi.csv')
BMI = pd.DataFrame(df)

关于这个错误,发生这个错误是因为Height不是df的列之一。我建议你在用seborn绘图之前检查一下这个 Dataframe 的内容/形状/列。这可能是你的.csv的分隔符有问题。

sns.relplot(x = 'Height', y = 'Weight', data=df)

相关问题