I have a dataset looks like this:

I want to split the second column and then append the values like this using python or pandas:

How could I change it? Thanks
You can make use of explode
df = pd.DataFrame({'A': [1, 2, 3, 4],
'B': ['ab,s', 'a,s,d,f', 'rk,lw', 'get,me']})
# Split by each comma
df.B = df.B.str.split(',')
df.explode('B')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With