The dictionary has the following key-value pairs:
{
'Target_Tab': 'employees',
' Target_Col': 'empp_id last_name first_name',
'Source_Col': 'emp_id l_name f_name',
'Source_Tab': 'employee'
}
I'm writing this dictionary into a CSV file and so far I've got this:
Source_Tab Source_Col Target_Tab Target_Col
employee emp_id last_name first_name employees empp_id l_name f_name
I want to write the Source _col and Target_col values in different rows. Se below is what I need:
Source_Tab Source_Col Target_Tab Target_Col
employee emp_id employees empp_id
last_name l_name
first_name f_name
My code is as follows:
import pandas as pd
d = [sdict]
d2 = []
col = ["Source_Table","Source_Columns","Target_Table","Target_Columns"]
for i in d:
temp = {}
for c in col:
if c in i:
temp[c] = i[c]
else:
temp[c] = ''
d2.append(temp)
df2 = pd.DataFrame(d2, columns=col)
df2.to_csv('test21.csv', index=False)