I want to add new rows and add a new column based on a existing column. For example let's say I have following Dataframe:
A B
1 a
2 b
3 c
4 b
And a dictionary with the unique column B values as keys. Each key is associated with a list of values. These values are used for the new rows and column:
{a: [x, y, z], b: [x, w, r], c: [x, q]}
The transformation should result in the following Dataframe:
A C
1 x
1 y
1 z
2 x
2 w
2 r
3 x
3 q
4 x
4 w
4 r
I know how to add a new column but I'm stuck with trying to replicate the rows. What is the most efficient solution to this problem? Do I update the existing Dataframe or create a new one?
Update
The operation will be used on a large dataframe (20 milion+ rows) using Dask.