I have two data frames:
Dataframe 1 (project data)
project_data = pd.DataFrame({'record_id' : ('1','2','3'), 'account_number' : ('123','124','125'), 'city' :('Vancouver','Miami','Dublin'),'salary' :(70000,80000,65000)})
Dataframe 2 (project data dictionary)
data_dict = pd.DataFrame({'variable_name' : ('record_id','account_number','city','salary'), 'form_name' : ('crosswalk_form','crosswalk_form','demographics','demographics')})
I want to be able to bring in the form_name
variable from Dataframe 2 (data dictionary) but don't know how to go about this as there is no common column to join between the data frames.
I was hoping to ask is there a way to join from the column headers in Dataframe 1 (project data) to the column variable_name
in Dataframe 2 (data dictionary). or would I need to reshape one of the data frames (possibly Dataframe 1)?
Possible output
merged_data = pd.DataFrame({'record_id' : ('1','2','3'), 'account_number' : ('123','124','125'), 'city' :('Vancouver','Miami','Dublin'),'salary' :(70000,80000,65000),'form_name' : ('crosswalk_form','crosswalk_form','demographics')})
I want this form_name
column to categorize the variables for some descriptive statistics I want to do further along. Thanks.