I'm very, very new to python and am looking for the best way to lookup and change the column header of a json api (that I have normalized via pandas) with the values from a second api from the same source. For brevity I've not posted the whole of the code, just the sections to do with the data.
name_df (lookup table)
name = response.json()
df = json_normalize(name['fields'],sep="_")
name_df = df[df.columns[1:3]]
print(name_df.head())
key label
0 field_18 Client_ID
1 field_16 Client Name
2 field_19 Client Code
3 field_26 Client Type
4 field_70 Third Party
etc...
data_df (data table)
data = response.json()
json_normalize(data)
data_df = json_normalize(data['records'],sep="_")
print(data_df.head())
field_16 field_16_raw field_18 field_18_raw field_19
Amazon Amazon 123 123 AMZ
WallMart WallMart 888 888 WLM
etc...
data_df.columns.values
['field_16' 'field_16_raw' 'field_18' 'field_18_raw' 'field_19'
'field_19_raw' 'field_26' 'field_26_raw' 'field_422' 'field_70'
'field_70_raw' 'field_71' 'field_71_raw']
My required output is
Client Name Client Name_raw Client_ID_18 Client_ID_18_raw Client Code
Amazon Amazon 123 123 AMZ
WallMart WallMart 888 888 WLM
etc...
I have been researching methods, however I'm not quite at the stage of being able to adapt the answers I've found to my use case - especially with the complexity of the _raw value appearing in the data table but not the lookup table. I can see the shape of the solution here, however it's using lookups to rows rather than columns so when I try to adapt it's not working.
Elegant way to replace values in pandas.DataFrame from another DataFrame
I'm also struggling to find a way to replace the variables of field_X rather than have to name the columns specifically. And I'm at the point now of overcomplicating where I am positive there must be a simple answer.
Thanks in advance for any advice