I need to perform the following operations in a loop: Select a slice of a pandas dataframe, then modify values of the slice (specifically, winsorize the data), then write the modified values back to the slice. What is the best practice for this? I have tried several ways, but the resulting column is usually full of NaNs.
for value in list_values:
temp_df = df.loc[df["Column_a" == value]]
transformed_data = pd.Series(mstats.winsorize(temp_df["Column_b"], limits=[0.05, 0.05])
df.loc[df["Column_a" == value, "Column_b]] = transformed_data
Any help is very appreciated. Thanks!