I have DataFrame and I need to derivate a new column based on the value of an existing column.
class SomeClass:
def reduce(self, x):
if x < 1:
return x ** 2
return np.sqrt(x)
def penalize_performance(self, df):
df['sqrt'] = df.apply(lambda x : self.reduce(x.perf), axis=1)
return df
The result is correct but I get the SettingWithCopyWarning warning:
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
How to I fix the syntax, to avoid the issue ?