我的第一个DataFrame代码:
data = {'Sr.No.': Sr_no,
'CompanyNames': Company_Names,
'YourChoice1': ['1','2','3','4','5','6','7','8','9'],
'YourChoice2': ['1','2','3','4','5','6','7','8','9']}
df = pd.DataFrame(data, columns = ['Sr.No.', 'CompanyNames','YourChoice1','YourChoice2'])
.csv文件中此数据帧的输出为:
第二个DataFrame代码:
data = {'BB': {'Field1': {'Previous Data': ['1','2','3','4','5','6','7','8','9'],
'Current Data': ['1','2','3','4','5','6','7','8','9']},
'Field2': {'Previous Data': ['1','2','3','4','5','6','7','8','9'],
'Current Data': ['1','2','3','4','5','6','7','8','9']},
'Field3': {'Previous Data': ['1','2','3','4','5','6','7','8','9'],
'Current Data': ['1','2','3','4','5','6','7','8','9']}
},
'MD': {'Field1': {'Previous Data': ['1','2','3','4','5','6','7','8','9'],
'Current Data': ['1','2','3','4','5','6','7','8','9']},
'Field2': {'Previous Data': ['1','2','3','4','5','6','7','8','9'],
'Current Data': ['1','2','3','4','5','6','7','8','9']}
}
}
form = {(outerKey,midKey,innerKey): values for outerKey, midDict in data.items() for midKey, innerDict in midDict.items() for innerKey, values in innerDict.items()}
df.to_csv('CSV_File_Name.csv', index=False)
此数据帧的输出为:
我想组合这些数据帧,以便获得以下期望的输出: