I have tried several versions but all of them throw a warning, starting with:
colName = 'age'
df_plot[colName][df_plot[colName]>10] = 10
SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. See the caveats in the documentation:http://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
Based on the link from the warning then:
df_plot.loc[:, (colName, df_plot[colName]>10)] = 10
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
Next
df_plot.loc[colName, df_plot[colName] > 10] = 10
TypeError: 'Series' objects are mutable, thus they cannot be hashed
And finally based on a stack-overflow answer also:
df_plot[colName] = df_plot[colName].apply(lambda x: [y if y <= 10 else 10 for y in x])
TypeError: 'float' object is not iterable
What am I doing wrong here?
df_plot.loc[df_plot[colName]>10, colName] = 10?df_plot[colName] = df_plot[colName].apply(lambda x: x if x <= 10 else 10)