I have datafremae like this
product_title variation type product_price attribute
0 Chauvet DJ [Black, White] [899.99, 949.99] ['<p>apple,banana<p>', '<p>yewllow,orange,blue</p>']
my expected dataframe will be look like this
product_title variation type product_price attribute
Chauvet DJ Black 899.99 <p>apple,banana<p>
Chauvet DJ White 949.99 <p>yewllow,orange,blue</p>
I tried this code:
data["variation type"] = data["variation type"].apply(str).str.strip('[]').apply(str).str.replace("'","").apply(str).str.split(',')
data["product_price"] = data["product_price"].apply(str).str.strip('[]').apply(str).str.replace("'","").apply(str).str.split(',')
data["attribute"] = data["attribute"].apply(str).str.strip('[]').apply(str).str.replace("'","").apply(str).str.split(r",(?=')",expand=True)
data = data.explode(['variation type', 'product_price','attribute'])
getting this error:
ValueError: columns must have matching element counts
apple,banana
', '
yewllow,orange,blue
']` I have two item in my list but the problem as I use split by comma so it's aslo counting the comma inside my inverted quote `'yewllow,orange,blue
']` . We need to only count comma after the inverted quote. – boyenec May 31 '22 at 11:16