Skip to content
Advertisement

Transform dataframe format

How do I convert the following dataframe from df1 to df2?

JavaScript

Thanks in advance!

Advertisement

Answer

You could try as follows. Apply .str.split to columns a and b in a loop, each time exploding the result. This will get us 2 pd.Series and we use pd.concat to put them together. After this, we just need to assign col c, and reset the index. So:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement