[Solved] Is there way to replace ranged data (eg 18-25) by its mean in a dataframe?
There are several ways to transform this variable. In the picture I see, that there are not only bins, but also value ’55+’, it needs to be considered. 1) One liner: df[‘age’].apply(lambda x: np.mean([int(x.split(‘-‘)[0]), int(x.split(‘-‘)[1])]) if ‘+’ not in x else x[:-1]) It checks whether the value contains ‘+’ (like 55+), if yes than the … Read more