Python Forum
Error in find pearson correlation function
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Error in find pearson correlation function
#2
This is a good example of where the very last line of the error is sufficient to show the cause of the problem (although not necessarily to fix it!).

TypeError: unsupported operand type(s) for /: 'str' and 'int'

You are trying to work out the correlation coefficient of a column that includes strings.

numpy is trying to calculate the correlation coefficient of each pair of columns, but column 1 (functional groups) is all strings, so when numpy tries to compute the average, it adds up all those strings (concatenation) to get one large string, then tries to divide by the number of rows.

I'm not sure how to fix that, there doesn't seem to be any facility in np.corrcoef to select which columns (or rows) are used.

By the way, the code you have copied and pasted here seems to be different from the code in your screen shot.
Reply


Messages In This Thread
RE: Error in find pearson correlation function - by stevendaprano - Mar-01-2022, 03:41 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I am getting a valueError. And not sure why? My goal is to visualize the correlation ReadytoCode 0 574 Dec-11-2023, 05:33 AM
Last Post: ReadytoCode
  Error when using FIND WJSwan 2 952 Jan-27-2023, 05:49 AM
Last Post: deanhystad
  how can a function find the name by which it is called? Skaperen 18 3,657 Aug-24-2022, 04:52 PM
Last Post: Skaperen
  How to increase the size of a png picture for the heatmap of the correlation? lulu43366 9 3,722 Oct-06-2021, 04:15 PM
Last Post: deanhystad
  How to remove a column or two columns in a correlation heatmap? lulu43366 3 5,414 Sep-30-2021, 03:47 PM
Last Post: lulu43366
  Getting 'NoneType' object has no attribute 'find' error when WebScraping with BS Franky77 2 5,424 Aug-17-2021, 05:24 PM
Last Post: Franky77
  pdfminer package: can't find exgtract_text function Pavel_47 7 5,429 Jan-25-2021, 03:31 PM
Last Post: Pavel_47
  List of error codes to find (and count) in all files in a directory tester_V 8 3,849 Dec-11-2020, 07:07 PM
Last Post: tester_V
  How do I find if a function has been defined? AndyHolyer 3 2,348 Jul-24-2020, 01:39 PM
Last Post: Gribouillis
  Cant find root cause of thread.lock error burlyboys 0 1,590 May-18-2020, 12:51 PM
Last Post: burlyboys

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020