I would like to explode a column Col1 of a dataframe and for all the replicated rows, set a specific value z for a given column Col2.
For example if my dataframe df is:
| Col1 | Col2 | Col3 |
|---|---|---|
| [A,B,C] | x | y |
I would like to find a way using df.explode("Col1") and achieve:
| Col1 | Col2 | Col3 |
|---|---|---|
| A | x | y |
| B | z | y |
| C | z | y |
Thank you for any idea.
Col1that you would like to change inCol2?Col1is the column that I want to explode. A, B and C are also dummy variables.df.explode('Col1')thenCol1will have A,B,C,Col2will have all x's andCol3will have all y's. What is the logic for the z's to come in?