1

I am trying to extract the content in the last parenthesis at the end of each of the following rows:

      Text

    "«A mio avviso, e credo non solo mio, (17-11-2020 12:42:05)"
     "Roma, 17 nov – Dalle elezioni, non è facile (…)\n (17-11-2020 12:42:04)"
     'Decine di avvocati del libero foro di tutte le regioni  ... (17-11-2020 12:41:08)'
     "Ci sono riusciti: vi stanno facendo odiare l'un l'altro (17-11-2020 12:41:01)"
     'Luciano ,\xa0 coreografo, esprime la sua opinione e il mondo de... (17-11-2020 12:40:01)'
    

I followed the answers here: Pandas - Get values within parentheses of a panda dataframe column, and tried with:

df['Datetime'] = df['Text'].str.extract(r"\(([A-Za-z]+)\)", expand=False)

but I did not get any value, only NaN. My expected output should be:

    Datetime
    17-11-2020 12:42:05
    17-11-2020 12:42:04
    17-11-2020 12:41:08
    17-11-2020 12:41:01
    17-11-2020 12:40:01
    

Could you tell me how I need to change my code to get the expected output?

1 Answers1

1

Please extract the characters between () at the end of line

df['Datetime']=df.Text.str.extract('(?<=\()(.*?)(?=\)$)')
wwnde
  • 26,119
  • 6
  • 18
  • 32