My datatable is below.
menu_nm | dtl | rcp | |
---|---|---|---|
0 | sandwich | amazing sandwich!!! | bread 10g |
1 | hamburger | bread 20g, vegetable 10g | ??? |
2 | salad | fresh salad!!! | apple sauce 10g, banana 40g, cucumber 5g |
3 | juice | sweet juice!! | orange 50g, water 100ml |
4 | fruits | strawberry 10g, grape 20g, melon 10g | ??? |
and I want to get this datatable
menu_nm | dtl | rcp | |
---|---|---|---|
0 | sandwich | amazing sandwich!!! | bread 10g |
1 | hamburger | bread 20g, vegetable 10g | |
2 | salad | fresh salad!!! | apple sauce 10g, banana 40g, cucumber 5g |
3 | juice | sweet juice!! | orange 50g, water 100ml |
4 | fruits | strawberry 10g, grape 20g, melon 10g |
I want to shift row 1, 4 to rcp column, but I can’t find method or logic that I try.
I just know that shifting all row and all column, I don’t know how I can shift certain row and column.
If you know hint or answer, please tell me. thanks.
>Solution :
assumption: rcp column contains "???" that needs to be replaced with the a values from dtl
# create a filter where value under rcp is "???"
m=df['rcp'].eq('???')
# using loc, shift the values
df.loc[m, 'rcp'] = df['dtl']
df.loc[m, 'dtl'] = ""
df
menu_nm dtl rcp
0 sandwich amazing sandwich!!! bread 10g
1 hamburger bread 20g, vegetable 10g
2 salad fresh salad!!! apple sauce 10g, banana 40g, cucumber 5g
3 juice sweet juice!! orange 50g, water 100ml
4 fruits strawberry 10g, grape 20g, melon 10g