I know that kind of these questions have been raised already, but for my specific problem I couldn't find any answers.
I have a csv with a lot of values in a column 'score'. If one value is greater than 0,001, I want to replace it with 1. If the value is smaller than -0,001, I want to replace it with -1. All values between needs to be removed.
I have tried the following:
import pandas as pd
import numpy as np
df = pd.read_csv('test.csv')
a = np.array(df['score'].values.tolist())
df['text']=np.where(a > 0.001, 1, a).tolist()
df['text']=np.where(a < -0.001, -1, a).tolist()
# Second try
#df['score']=df['score'].apply(lambda x: [-1 if x <= 0.001 else x])
#df['score']=df['score'].apply(lambda x: [1 if x > 0.001 else x])
The output only shows me the second expression, but ignores the first one, in both cases. So at this example, I receive a list where each value < -0.001 = -1, nothing more.
Can anybody help me?