I have the following DataFrame in Pandas:
import pandas as pd
import numpy as np
df = pd.DataFrame([(1, 1, 1, 0),
(2, 0, 0, 2),
(3, 0, 1, 3),
(4, 5, 3, 0)],
columns=list('abcd'))
I need to implement the following function into that DataFrame:
I'm trying to use the apply()
function below:
dfs = df.apply(lambda x: np.mean(x)+2*np.std(x) if x > np.mean(x)+2*np.std(x) else x, axis = 0, result_type='broadcast')
dfs
I'm getting the following error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Not really sure what it means, or where should i use those a.empty, a.bool()...
to fix it.