samedi 17 juillet 2021

python convert text rows to dictionary based on conditional match

I have the rows below in a text file and need help on how write an if condition in a for loop that check if the row.startswith('name') then take the next row value and store is in a variable called name. Similarly for dob as well.

Once the for loop completes the output should be a dictionary as below which i can convert to a pandas dataframe.

name
john

dob
12/08/1984

current company
google

Final Ouput

data = {"name":"john", "dob": "12/08/1984"}

Aucun commentaire:

Enregistrer un commentaire