I have got some data which I have read into dictionary of dictionaries
EDIT : Posting original data format
Original Data is one excel files for each user every month
Alpha - Jan 2018 .. following format
Score
English 70
Social Science 80
Maths 90
History 45
Science 50
I read all these excels into python and get them into dictionaries as mentioned below. Some students may miss some exams hence for those months their data will be missing. Hence variation will be complete month data missing for few students.
{alpha: {u'Jan-2018': {'Eng': '70', 'math': '90', 'sci': '50'}, u'feb-2018': {'Eng': '75', 'math': '85', 'sci': '60'}, u'mar-2018': {'Eng': '60', 'math': '92', 'sci': '40'}}
{beta : {u'Jan-2018': {'Eng': '30', 'math': '50', 'sci': '40'}, u'feb-2018': {'Eng': '55', 'math': '45', 'sci': '70'}, u'may-2018': {'Eng': '50', 'math': '52', 'sci': '45'}}
{gamma : {u'Jan-2018': {'Eng': '50', 'math': '50', 'sci': '40'}, u'feb-2018': {'Eng': '55', 'math': '75', 'sci': '40'}, u'may-2018': {'Eng': '56', 'math': '59', 'sci': '35'}}
I want to get these on Excel in following format. On sheet 1 it should publish only Eng data for different months and on second sheet math data and third sci data. For whichever month for someone data is missing, that should be left blank or maybe 0
Sheet1(Eng):
Jan-2018 Feb-2018 Mar-2018 May-2018
alpha 70 75 60 0
beta 30 55 0 50
gamma 50 55 0 56
similarly for other two sheets.
I have tried following code, however there are two issues with it:
- It doesn't consider the missing months, and prints sequentially
It doesn't print the month name on top of the every column
List1 contains dict of dicts mentioned above
alleng = {} allmath = {} allsci = {} for i in list1: englist = [] mathlist = [] scilist = [] for m in list1[i]: for h in list1[i][m]: value1 = list1[i][m][h] if h == 'Eng': englist.append(value1) if h == 'Math': mathlist.append(value1) if h == 'Sci': scilist.append(value1) alleng[i] = englist allmath[i] = mathlist allsci[i] = scilist writer = ExcelWriter('final-sheet.xlsx') frame = pd.DataFrame.from_dict(allsci, orient='index') frame = frame.transpose() frame = frame.transpose() frame.to_excel(writer , sheet_name = 'Sci') frame1 = pd.DataFrame.from_dict(alleng, orient='index') frame1 = frame1.transpose() frame1 = frame1.transpose() frame1.to_excel(writer , sheet_name = 'Eng') frame2 = pd.DataFrame.from_dict(allmath, orient='index') frame2 = frame2.transpose() frame2 = frame2.transpose() frame2.to_excel(writer , sheet_name = 'Math')
I also tried using following solution, however it didn't help: