I want to replicate data frame rows by splitting the contact number, I'm trying several ways but unable to do so. Please help
Input:
df
col1 mob_no col3
a 9382949201/3245622535 45
b 8383459345/4325562678 67
c 8976247543/1827472398 89
d 7844329432 09
Expected output:
col1 mob_no col3
a 9382949201 45
a 3245622535 45
b 8383459345 67
b 4325562678 67
c 8976247543 89
c 1827472398 89
d 7844329432 09
Try with str.split
+ DataFrame.explode
:
df['mob_no'] = df['mob_no'].str.split('/')
df = df.explode('mob_no')
col1 mob_no col3
0 a 9382949201 45
0 a 3245622535 45
1 b 8383459345 67
1 b 4325562678 67
2 c 8976247543 89
2 c 1827472398 89
3 d 7844329432 09
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