I have a function, and a rule to be applied on df.
def apply_rule(df, rule):
df['legal'] = df.apply(rule)
def greater_than_mean_plus_1_std():
return df['col1']>df['col1'].mean()+df['col1'].std()
apply_rule(df, greater_than_mean_plus_1_std)
I want to apply rule on my df that can make me a new column that tells me if the value of row is greater than mean+std or not.
But with df.apply(), I can't use df.mean() and df.std() here.
AttributeError: 'float' object has no attribute 'mean'
Is there a way to do so? Or I have to use methods other than df.apply()?
edited:
print(df.head())
col1
0 7.2
1 7.2
2 7.2
3 7.2
4 7.2
expected output:
col1 legal
0 7.2 False
1 7.2 False
2 7.2 False
3 7.2 False
4 7.2 False