Home > Software design >  How to get a substring between two substrings in pandas?
How to get a substring between two substrings in pandas?

Time:12-26

I Have a column in Dataframe in which the data is as below.

Invoice Number
Being InvoiceNC/0095/2022.23 Dt. 06.10.2022
Black Toner Cartridge agst InvoiceNC/0098/2022.23 dt 10.10.2022
Being amount vide InvoiceS0001236 Dt. 03.10.2022
Being amount vide InvoiceS0001235 Dt. 03.10.2022

I'd like to remove everything from the column but the string between 'Invoice' and next " ".

Any help will be appretiated.

CodePudding user response:

s = df['Invoice Number'].str.extract('Invoice(\S )')

s

    0
0   NC/0095/2022.23
1   NC/0098/2022.23
2   S0001236
3   S0001235

CodePudding user response:

you can use :

df['Invoice Number']=a
l=[]
k=[]
for i in range(len(a)):
    l.append(a[i].split('Invoice')[1])
    k.append(l[i].split(' ')[0])

df['Invoice Number']=k# replace  in df by new values
  • Related