1

I want to make a kdeplot for my pandas dataframe. I used the code below:

mean = [0,0]

cov = [[1,0],[0,100]]

dataset2 = np.random.multivariate_normal(mean,cov,1000)

dframe = pd.DataFrame(dataset2,columns=['X','Y'])

sns.kdeplot(dframe)

And got this error message:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-20-852468cc1da8> in <module>()
      7 dframe = pd.DataFrame(dataset2,columns=['X','Y'])
      8 
----> 9 sns.kdeplot(dframe)

9 frames
/usr/local/lib/python3.6/dist-packages/pandas/core/internals/construction.py in extract_index(data)
    385 
    386         if not indexes and not raw_lengths:
--> 387             raise ValueError("If using all scalar values, you must pass an index")
    388 
    389         if have_series:

ValueError: If using all scalar values, you must pass an index

How should I amend my code?

Note: It works when I instead use:

sns.kdeplot(dframe.X,dframe.Y)
2
  • 1
    sns.kdeplot(dframe) is not valid syntax, as per seaborn.kdeplot. You have not properly specified the parameters in order. Commented Dec 23, 2020 at 10:29
  • 1
    Ok, thank you! So, the code I wrote seems to be deprecated because it worked before (according to a Udemy course). Commented Dec 23, 2020 at 10:40

1 Answer 1

2

you need to assign the columns to the plot

sns.kdeplot(data=dframe,x='X',y='Y')
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.