I’m working on a dataset where a column is having numbers separated by commas.
I want to convert the values into integer and obtain their mean value to replace with the current anomaly.
ex: 50,45,30,20
I want to get the mean value and replace it with current value
>Solution :
You can simply define a function that unpack those values and then get the mean of those.
def get_mean(x):
#split into list of strings
splited = x.split(',')
#Transform into numbers
y = [float(n) for n in splited]
return sum(y)/len(y)
#Apply on desired column
df['col'] = df['col'].apply(get_mean)