I am a very inexperienced programmer, this is my first question on the Data Science StackExchange, I sorry if it is formatted poorly or comes across as basic. For some strange reason, in Python, whenever I try to run a correlation function on the population density & total cases per million columns of my COVID-19 DataFrame (which I imported/read into Spyder as a csv), I keep getting the same long error message, namely, "ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()." regardless of whether I use the correlation function from Pandas or Numpy. My first thought was that this error was caused by the presence of null values in those columns, so I used df.dropna(), then ran the correlation function again but I got the same "ValueError", so I have no idea what is going on here, I was able to run a correlation on those same columns just fine in RStudio which I am equally unskilled and inexperienced with.
My corr() function in Python keeps resulting in an "ValueError: The truth value of a Series is ambiguous..." [closed]
You should look at the documentation. You do not pass the column names as an argument.
subset_df = df[['col1', 'col2']] subset_df.corr()
That should solve this for you.
method ='pearson'in your parenthesis, this way :
df.corr(df[...], df[...], method ='pearson'). Not sure if it will work but there seems to be an error on which method you use / on the fact that you don't precise the method for the corr function $\endgroup$