I'm trying to update the pandas data frame by logical condition but, it fails with below error,
df[df.b <= 0]['b'] = 0 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 do I get this working?
Data:
df = pd.DataFrame({'a': np.random.randn(4), 'b': np.random.randn(4)}) a b 0 1.462028 -1.337630 1 0.206193 -1.060710 2 -0.464847 -1.881426 3 0.290627 0.650805 I am learning pandas. In R, syntax is like below,
df[df$b <= 0]$b <- 0