Home > database >  Lookup between two dataframes
Lookup between two dataframes

Time:06-09

I have a dataframe like below from an API response:

enter image description here

However, The API can give more variables like street, direction etc., So, I need to create an output from the API response which automatically define null. Example like below

enter image description here

For this I created a list of all the variables I want in the output and tried and match API response dataframe to the output dataframe.

Any help will be greatly appreciated

Thanks in advance

CodePudding user response:

IIUC use DataFrame.reindex by list, if column not exist is filled by missing values:

L = ['house','house_number',..., 'street', 'direction']
df = df1.reindex(L, axis=1)
  • Related