-1

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`

Roxy
  • 1,015
  • 7
  • 20
Albert
  • 1
  • 1
  • 2
  • 1
    Please check `df.columns`. Maybe there are extra spaces in the column names? – JohanC Nov 22 '22 at 11:49
  • Where did you download the bmi.csv data? I would recommend to use [Kaggle - BMI data](https://www.kaggle.com/datasets/yasserh/bmidataset). Works easily without an issue on reproducing the above code implementation. – Roxy Nov 22 '22 at 13:37
  • For others searching for this error, it can be also caused by having the df as first unnamed argument to the seaborn plotting function. – Melkor.cz Jul 21 '23 at 08:29

1 Answers1

0

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

Timeless
  • 22,580
  • 4
  • 12
  • 30
  • Hi, I deleted BMI later because I didn't need it. But yeah there indeed was a problem with my .csv file. I changed the csv file and got it to work. Thank you very much! – Albert Nov 22 '22 at 15:16