Or is there a much better solution (for example via a json string)?ĭict(field.split(': ') for field in line.split('|'))Īssuming you already split your data into lines you then need to process them into records such as: )ĭf = df.apply(lambda x:x.split('|'))ĭf = df.apply(get_dict)įinal_df = pd.om_dict(dict_list) Name: chris| dob: 09-12-1965| address: 485 Green Avenue| state: California| Telephone Number: 51ĭesired output: Name | dob | address | mobile | telephone number | state | Name: liam| dob: 12-08-1986| address: 4853 498 Fairmont Avenue| telephone number: 70 Sample file: name: john| dob: 10-06-1960| address: 4853 Radio Park Drive The challenge is that I don't know in advance what the keys (column headers are) and in what order they are. I have a text file as shown below in the sample that I want to convert to a csv file (currently using Pandas).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |