My corr() function in Python keeps resulting in an "ValueError: The truth value of a Series is ambiguous..."

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.

Topic numpy ipython correlation pandas python

Category Data Science


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.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.