Simplified df where some rows contain additional entries in another flavor that should be another row:
values more values flavor another flavor
0 6 foo caramel chocolate
1 4 baz vanilla NaN
df = pd.DataFrame({"values": [6, 4],"more values": ["foo", "baz"],"flavor": ["caramel", "vanilla"],"another flavor": ["chocolate", np.nan],})
We need to add another row containing values from other columns, populating flavor with values from another flavor. We'd then drop another flavor to get desired_df:
values more values flavor
0 6 foo caramel
1 6 foo chocolate
2 4 baz vanilla
desired_df = pd.DataFrame({"values": [6, 6, 4],"more values": ["foo", "foo", "baz"],"flavor": ["caramel", "chocolate", "vanilla"],})
What's a practical way to do this? Is there an expression for this I could search for as a keyword?