1

I'm working on big text data frame that looks like this:

ID  CustomerName     topics_seq  topics_count   log  
812199329          ['Due'/'Shift']      2     ["Agent: Hello", "Customer: Hello: Can you help?"] 
813447595          ['Shift']            1     ["Customer: Alright let's go", "Agent: Due to"]

I would like to split, to a new row the log column for each agent or customer, so something like this:

ID  CustomerName     topics_seq  topics_count   log  
812199329.1          ['Due'/'Shift']      2     ["Agent: Hello",
812199329.2          ['Due'/'Shift']      2     "Customer: Hello: Can you help?"]
813447595.1          ['Shift']            1     ["Customer: Alright let's go",
813447595.2          ['Shift']            1     "Agent: Due to"]

I wrote something like that but this is not what I wanted:

df = df['log'].str.split('Agent|Customer', '/n')

Please help.

Tal1992
  • 51
  • 5
  • hi, perhaps might be of interest https://stackoverflow.com/questions/17116814/how-to-split-text-in-a-column-into-multiple-rows – jspcal Sep 29 '22 at 20:57
  • 1
    df.explode("log") ? – Lucas M. Uriarte Sep 29 '22 at 20:59
  • is the example the same as your actual data? is it a simple as exploding by the comma? – Umar.H Sep 29 '22 at 21:03
  • I saw that post but mine is different, I need to split text and base on condition (split after every agent/customer). df.explode("log") didn't do anything. Any suggestion? Thanks for the help – Tal1992 Sep 30 '22 at 15:13

1 Answers1

0

Explode the log column:

df.explode('log')
  • Did not do anything, the log column did not get split. Is there a way to split by condition, after every agent/customer is mentioned? – Tal1992 Sep 30 '22 at 15:14