Python Forum
How to extract specific key value pair from string?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to extract specific key value pair from string?

I am new to python programming and need your help.

I have a Notes Column in excel file which contains data as below

ROW 1: Country:USA

Serial Number: 00 DB C0 B1 E3 D5 05 7B 57 BE 3A BB FF D1 62 D6 A7
Address: 23 xys lane

Zip : 22102

ROW 2 : Country:India

Serial Number: 01 DB C0 B1 E3 D5 05 7B 57 BE 3A BB FF D1 62 D6 A7
City: Fairfax

I need to extract the Serial Number from the string and create a new column for it.

I have the below code to split based on (: & \n )but data is not consistent in each row so it is not splitting correctly.

 import openpyxl
import pandas as  pd

book = openpyxl.load_workbook(r'C:\Users\OneDrive - Fannie Mae\Info\test.xlsx')
user_data = book.get_sheet_by_name(str('test'))
df= pd.DataFrame([str(user_data[x][0].value) for x in range(1,user_data.max_row)])
df.columns = df.columns.str.replace(' ', '')
df1 = df.PluginOutput.str.split('\n',expand=True)

Please help !!!

Possibly Related Threads…
Thread Author Replies Views Last Post
  Using locationtagger to extract locations found in a specific country/region lord_of_cinder 1 243 Oct-04-2022, 12:46 AM
Last Post: Larz60+
  How to extract specific data from .SRC (note pad file) Shinny_Shin 2 421 Jul-27-2022, 12:31 PM
Last Post: Larz60+
  Getting the maximum value:key pair from a dictionary sean1 2 725 Jan-17-2022, 01:04 PM
Last Post: DeaD_EyE
  Extract a string between 2 words from a text file OscarBoots 2 1,105 Nov-02-2021, 08:50 AM
Last Post: ibreeden
Question [SOLVED] Delete specific characters from string lines EnfantNicolas 4 1,253 Oct-21-2021, 11:28 AM
Last Post: EnfantNicolas
  Extract specific sentences from text file Bubly 3 1,953 May-31-2021, 06:55 PM
Last Post: Larz60+
Question How to extract multiple text from a string? chatguy 2 1,591 Feb-28-2021, 07:39 AM
Last Post: bowlofred
  Extract continuous numeric characters from a string in Python Robotguy 2 1,768 Jan-16-2021, 12:44 AM
Last Post: snippsat
  Auto re-pair / re-sync Controller via Script? User3000 2 1,619 Nov-30-2020, 11:42 AM
Last Post: User3000
  Printing string at specific position on terminal - not showing __Mathieu__ 1 1,482 Sep-07-2020, 10:32 AM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020