I'm trying to put a particular value in the data frame row to other rows also if it matches a condition. However i'm not getting what is expected. Can someone help to get the value as shown in the expected value column. Thanks in advance! Result I'm getting is Code Expected_Cum_Value Value ValueCount ResultValue
0 100 1000 NaN NaN NaN
1 100 1000 1000.0 1.0 1000.0
2 100 1000 2000.0 2.0 NaN
3 200 2000 NaN NaN NaN
4 200 2000 2000.0 1.0 2000.0
0 100 1000 NaN NaN NaN
1 100 1000 1000.0 1.0 1000.0
2 100 1000 2000.0 2.0 NaN
3 200 2000 NaN NaN NaN
4 200 2000 2000.0 1.0 2000.0
df = pd.DataFrame(data = {'Code':[100,100,100,200,200], 'Value':[np.nan,1000,2000,np.nan,2000], 'ValueCount':[np.nan,1,2,np.nan,1], 'Expected_Cum_Value':[1000,1000,1000,2000,2000],}) for i in df['Code'].unique(): print(i) Insu1= df.loc[((df['Code'] == i)&(df['ValueCount']==1)), 'Value'] print(Insu1) df.loc[((df['Code'] == i)), 'ResultValue'] = Insu1