I have two dataframes. Data and metadata.
A reproducible example:
Data has 32 column names as X1, X2, etc.
{'X1': {0: '11.89%', 1: '10.71%'},
'X2': {0: 54734.0, 1: 55742.0},
'X3': {0: 80364.0, 1: 114426.0}}
Metadata has the same X1, X2.
{'Variable': {0: 'X1',
1: 'X2',
2: 'X3'},
'Definition': {0: 'Test',
1: 'Test',
2: 'Test'}}
My desired output - match rows by X1, X2 etc and have metadata Definition
column as names of my data.
So far I tried to do the following:
# Drop X1, X2, X3 for from metadata
del metadata['Variable']
# Hardcode column names without matching
loan_data.columns = metadata
It gives me an output, but I need to clean it additionally with regex
[('Column1 text',),
('Column2 text.',),
('Column3 text.',),
I am sure there is a more elegant way. Thanks for tips!
UPDATED
df1 = pd.DataFrame([[1, 2], [1, 3], [4, 6]], columns=['X1', 'X2'])
df2 = pd.DataFrame([['X1', 'Definition1'], ['X2', 'Definition1']], columns=['Variable', 'Definition'])
df_output = pd.DataFrame([[1, 2], [1, 3], [4, 6]], columns=['Definition1', 'Definition2'])