I have three columns like follows:
Sales Population Income Price
14 48777.0 285.0 nan
17 12550.0 1.0 nan
24 15664.0 14.0 14
9 23796.0 24.0 0
20 40149.0 63.0 nan
75 39489.0 32.0 nan
I need to convert everything to per capita terms, that is for each element in sales, I need to divide it by the corresponding population. For example, for sales, I want to divide it by population to get per capita sales:
Per capita sales
14/48777
17/12550
...
The command I use is:
data['Per Capita Sales'] = data['Sales'] / data['Population']
But I got the following error:
TypeError: ufunc 'true_divide' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''
Does anyone know how to fix this? I have searched online how to divide one column by another column element-wise, but did not find a safe way to do it... Since the columns with values "nan" and "0" are in the numerator, I don't know why there could be an error...
Thank you very much for your help!
JavaScript questions and answers, JavaScript questions pdf, JavaScript question bank, JavaScript questions and answers pdf, mcq on JavaScript pdf, JavaScript questions and solutions, JavaScript mcq Test , Interview JavaScript questions, JavaScript Questions for Interview, JavaScript MCQ (Multiple Choice Questions)