In Python I am trying to split a column into multiple rows this
A B
ABC|XYZ|PQR 123
into
A B
ABC 123
XYZ 123
PQR 123
I have this code
df_wpipe = df[df['director'].str.contains("\|", na=False)]
df_wopipe = df[df["director"].str.contains("\|")==False]
for x in range(100):
df_a = df_wpipe.copy()
df_a['director'] = df_a['director'].str.split('\|').apply(lambda li: li[x] if len(li) == x+1 else None)
new_rows = df_wopipe.append(df_a)
if len(df_a.index)==0:
break
First str.contains("\|", na=False) seems not to be working because the df df_wpipe contains only 154 where is should have 500+ second the for loop seems not to append the rows. Could you please help. Thanks
This is unnest problem .
Or try something new