I have a dataframe like below from an API response:
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
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)