ValueError: Could not interpret value for parameter

9.6k Views Asked by At

load "bmi.csv" into the Dataframe and create a scatter plot of the data using relplot() with height on x-axis and weight on y-axis and color the plot points based on Gender and vary the size of the points by BMI index.

My code is:

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

I get:

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`

2

There are 2 best solutions below

1
Timeless On

Besides the error, why are you constructing a dataframe from a dataframe and also you're not using it ? I'm talking about BMI here :

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

And regarding the error, this one has occured because Height is not one of the columns of df. I suggest you to check the content/shape/columns of this dataframe before plotting with seaborn. It may be a problem with the separator of your .csv.

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

enter image description here

Dataset: https://github.com/aniketsoni1/BMI-Data-Insight-using-SVM/blob/master/bmi.csv

0
Xinwei Sher On

I encountered the same issue, and Melkor.cz's comment was the reason:

For others searching for this error, it can be also caused by having the df as first unnamed argument to the seaborn plotting function.