Home > Back-end >  split strings in a cell into different row, pandas
split strings in a cell into different row, pandas

Time:09-29

I need to split this cell in different rows in pandas dataframe, basically splitting strings but ignoring the comma inside quotes.

'one two three', 'don't split, this'

output would be like:

'one two three'
'don't split, this'

Thanks in advance

CodePudding user response:

Why not just use:

df['col'].str.split(r"(?<=')[,(\s|)](?=')")

Or if there always be a space after the comma, do:

s.str.split(r"(?<='), (?=')")
  • Related