'How to compare column elements to the column's mode?
I am trying to find the probability that a value in a column is equal to the columns mean. I have tried the following:
count = 0
for column_name, column_data in creoles[creoles.columns[2:]].iteritems():
mode = creoles[column_name].mode()
data = creoles[column_name].tolist()
for i in data:
for j in mode:
if i == j:
count += 1
baseline = round(count / len(data), 3)
count = 0
but I recieve the following Error:
A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead
I am not sure if that applies to my specific situation, or if it does how I would go about doing that. I've looked online for a while and couldn't find a solution. Thanks in advance
Solution 1:[1]
As the mean is just one favorable outcome, you could just divide the favorable outcome for all the possibilites, such as:
prob_eq_mean = 1/df['column'].count()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | luka1156 |
