I have such df
product type price
A 1 10
A 2 15
A 3 NAN
A 4 20
B 1 40
B 2 30
B 3 NAN
B 4 5
C 1 80
C 2 70
C 3 90
C 4 NAN
D 6 75
D 8 40
I want to update the value of price (Not necessarily NAN) based on another value
If (type == 3):
price == df['type' == 1]
elif ( type == 4):
price == df['type' == 2]
elif ( type == 8):
price == df['type' == 6]
Something like this the condition. I tried for each using the following:
df.loc[df['type'] == 3, 'price'] = df[df['type']==1]['price'].iloc[0]
The following way works just that the value 10 is replaced at both product A, B and C.
Is there a way that this value can be updated according to the product group. The expected outcome as following :
product type price
A 1 10
A 2 15
A 3 10
A 4 15
B 1 40
B 2 30
B 3 40
B 4 30
C 1 80
C 2 70
C 3 80
C 4 70
D 6 75
D 8 75
Note: using transform('first') may not be appropriate in this use case. Not necessarily each product will have all the type (1-10)
Thanks