Last answered:

30 Nov 2024

Posted on:

28 Dec 2023

0

sns.scatterplot error

Hi 365 Data Science

I do not understand why I have this error. Please advise


Thanks

2 answers ( 0 marked as helpful)
Super learner
This user is a Super Learner. To become a Super Learner, you need to reach Level 8.
Posted on:

04 May 2024

0

This is the signature of a scatterplot:

sns.scatterplot(
    data=None,
    *,
    x=None,
    y=None,
    hue=None,
    size=None,
    style=None,
    palette=None,
    hue_order=None,
    hue_norm=None,
    sizes=None,
    size_order=None,
    size_norm=None,
    markers=True,
    style_order=None,
    legend='auto',
    ax=None,
    **kwargs,
)

What this means is that when you use sns.scatterplot, it reads your first argument (if the name of the argument is not specified), as the data to be used, after the first argument, you need to specify the name of the argument you are passing. The correction needed to be made to your code is as follows:

sns.scatterplot(x=scatter["Area (ft.)"], y=scatter["Price"])

This made just two subtle differences to your code; passing the arguments as "x" and "y" respectively to specify what the arguments you passed stands for. Alternatively the following two version works just exactly the same way:

sns.scatterplot(data=scatter, x="Area (ft.)", y="Price")
sns.scatterplot(scatter, x="Area (ft.)", y="Price")

I guess the method has changed since this video was recorded.

I hope this helps both either the questioner or others or both.

Posted on:

30 Nov 2024

0

Hi, i had to write it directly refering to original data like that to make it works on my side:


sns.scatterplot(data=df_real_estate, x=df_real_estate["Area (ft.)"], y=df_real_estate["Price"],
                hue = df_real_estate['Building Type'],
                palette = ['black', 'darkblue', 'purple', 'pink', 'white'],
                s = 100)

Submit an answer