I want to add "1" in each row for columns "Score" where the below statement is true,
import pandas as pd
import numpy as np
df = pd.read_csv(Path1 + 'Test.csv')
df.replace(np.nan, 0, inplace=True)
df[(df.Day7 >= 500)]
I want to add "1" in each row for columns "Score" where the below statement is true,
import pandas as pd
import numpy as np
df = pd.read_csv(Path1 + 'Test.csv')
df.replace(np.nan, 0, inplace=True)
df[(df.Day7 >= 500)]
Could you please try following.
df['score']=np.where(df['Day7']>=500,1,"")
Or as per OP's comment(adding @anky_91's enhanced solution here):
np.where((df['Day7']>=500)&(df['Day7']<1000),1,"")
When we print the value of df
following will be the output.
Cat Day7 score
0 Advertisir 145
1 Blogs 56
2 Business 92
3 Classfied 23
4 Continuin 110
5 Corporate 1974 1