I want to parse some text within a dictionary, for example I want text with colons on the left and on the right those without colons. So that I can have those with colons as key and those without as values.
Here's the data:
x={0: {0: 'Name in home country:\n Kylian Mbappé Lottin\n Date of birth:\n Dec 20, 1998 \n Place of birth:\n \n Paris\xa0\xa0 \n Age:\n 22\n Height:\n 1,78\xa0m\n Citizenship:\n \n \xa0\xa0France \n Position:\n \n attack - Centre-Forward \n Foot:\n right\n Player agent:\n \n Relatives \n \n Current club:\n \n \n Paris Saint-Germain \n Joined:\n \n Jul 1, 2018 \n Contract expires:\n Jun 30, 2022\n Outfitter:\n Nike\n \n Social-Media:'}}
Then convert to pandas dataframe:
x = pd.DataFrame(x)
Attempts I have tried:
x[0][0].replace('\n', '').split("/")[0]
Which removes the white spaces but I cannot select for specific text and there's lots of spaces.
I've also tried:
x[0][0].replace('\n', ',').split(',')
This works much better as I can actually index what I wanted however because Date of birth has a comma then I get split dates but I'd rather have a single. But also I get many empty indexed values that have just a space and comma.
for example:
data = {}
for j in range(0, len(x[0][0].replace('\n', ',').split(','))):
for i in x[0]:
print(i.replace('\n', ',').split(',')[j])
Although I'm unsure how to set this up to get an expected outcome like below because of the different split sizes.
Expected outcome:
{'Name in home country:':["Kylian Mbappé Lottin"],
'Date of birth:':["Dec 20, 1998"],
'Place of birth:':["Paris\xa0\xa0"]
...
...
}