'Find the average of string in python [closed]

I have an string in python (with float and integer numbers)

string = '44,44,44,33'

I want to calculate the mean of that.

Note: I have one large dataframe, and in one column of the dataframe, I have such a string. I want to calculate the mean for all rows. I hope I there is an efficient way for that.

Thanks



Solution 1:[1]

l = string.split(',')
average = sum(int(k) for k in l)/len(l)

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 Mateo Vial