'split comma seperated column into many pandas

I have 5 columns with string values separated by comma. I want to split the column into required columns. For example I have two columns with entries (strings) below.

col1            col2
a,b,c,d         e,f,g,h,i
c,d             h,i

My required cols are:

cola    colb    colc   cold    cole    colf    colg    colh    coli
a        b        c      d       e       f       g       h       i
                  c      d                               h       i

I can split the columns and I have done coding, but I don't know how to do it the above way. Secondly, I want to split multiple column in one line code.

df1 = df2['col1'].str.split(',' , expand=True) # This only split one column col1. 

Thank you for your help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source