├── A Data Scientist Task.py ├── Python Excel 2.py ├── Python Excel 3-1.py ├── Python Excel 3-2.py ├── Python Excel 4.py ├── Python excel 1.py └── color_code.py /A Data Scientist Task.py: -------------------------------------------------------------------------------- 1 | # See full Toturial at my Youtube Channel(YB TV): https://www.youtube.com/channel/UCvnhhDKv5takEN412dmVW8g/featured 2 | # GitHab Page:https://github.com/yasser64b/ 3 | #Email: big3del@gmail.com 4 | 5 | 6 | from openpyxl import Workbook 7 | from openpyxl import load_workbook 8 | from openpyxl.styles import PatternFill, Border, Side, Alignment, Protection, Font, Color, colors, fills 9 | import numpy as np 10 | 11 | # loading the file 12 | wb = load_workbook('test results.xlsx') 13 | SheetNames= wb.sheetnames 14 | MeanMax=[] 15 | cols='abcdefghijklmnopqrstuvwxyz' 16 | 17 | for names in SheetNames: 18 | sheet_ranges = wb[names] 19 | for col in cols: 20 | data=[] 21 | header='' 22 | for row in range (1, 200): 23 | cellValue=sheet_ranges[col+str(row)].value 24 | if type(cellValue) is str: 25 | header=cellValue 26 | elif type(cellValue) is int or type(cellValue) is float: 27 | data.append(cellValue) 28 | if len(data)>0: 29 | MeanMax.append([names, header, len(data), np.mean(data), np.max(data)]) 30 | # print(MeanMax) 31 | 32 | wb1 = Workbook() 33 | ws1 = wb1.active # work sheet 34 | ws1.title = "tests" 35 | 36 | for j in range (0,21): 37 | means=[] 38 | maxes=[] 39 | for i in range (len(MeanMax)): 40 | if MeanMax[i][1]=='Test'+str(j): 41 | means.append(MeanMax[i][3]) 42 | maxes.append(MeanMax[i][4]) 43 | if len(means)>0: 44 | MeanT=np.mean(means) 45 | MaxT=np.max(maxes) 46 | _ = ws1.cell(column=j+1, row=1, value='test'+str(j)) 47 | _ = ws1.cell(column=1, row=1, value='test ranges') 48 | _ = ws1.cell(column=j+1, row=2, value=MeanT) 49 | _ = ws1.cell(column=1, row=2, value='Average') 50 | _ = ws1.cell(column=j+1, row=3, value=MaxT) 51 | _ = ws1.cell(column=1, row=3, value='Maximum') 52 | 53 | thin_border = Border(left=Side(border_style='dashed',color='FF000000'), 54 | right=Side(border_style='dashed',color='FF000000'), 55 | top=Side(border_style='thin',color='FF000000'), 56 | bottom=Side(border_style='thin',color='FF000000') 57 | ) 58 | 59 | thick_border = Border(left=Side(border_style='thin',color='FF000000'), 60 | right=Side(border_style='thin',color='FF000000'), 61 | top=Side(border_style='thin',color='FF000000'), 62 | bottom=Side(border_style='medium',color='FF000000') 63 | ) 64 | Double_border = Border(left=Side(border_style='dashed',color='FF000000'), 65 | right=Side(border_style='dashed',color='FF000000'), 66 | top=Side(border_style='double',color='FF000000'), 67 | bottom=Side(border_style='double',color='FF000000') 68 | ) 69 | 70 | #Define fill formating 71 | fill_cell = PatternFill(fill_type=fills.FILL_SOLID, 72 | start_color='00FFFF00',end_color='00FFFF00') 73 | 74 | for k in range (1,4): 75 | for l in range (1,22): 76 | ws1.cell(k,l).number_format='#,#0.0' 77 | ws1.cell(k,l).border=thin_border 78 | if k==1: 79 | ws1.cell(k,l).fill=fill_cell 80 | 81 | wb1.save('analyzed data.xlsx') 82 | -------------------------------------------------------------------------------- /Python Excel 2.py: -------------------------------------------------------------------------------- 1 | # See full Toturial at my Youtube Channel(YB TV): https://www.youtube.com/channel/UCvnhhDKv5takEN412dmVW8g/featured 2 | # GitHab Page:https://github.com/yasser64b/ 3 | #Email: big3del@gmail.com 4 | 5 | 6 | from openpyxl import Workbook # pip install openpyxl 7 | from openpyxl.styles import Font, Color, colors 8 | from openpyxl.utils import get_column_letter 9 | # see example 1 or 10 | listA=['DistanceA (m)',1,2,3,4,5,6,7,8,8,9,9,1,2,3,4,5,6,7,8,8,9,9,1,2,3,4,5,6,7,8,8,9,9] 11 | listB=['DistanceB (m)',1,2,3,4,5,6,7,8,8,9,9,1,2,3,4,5,6,7,8,8,9,9,1,2,3,4,5,6,7,8,8,9,9] 12 | L=[listA, listB,listA, listB,listA, listB,listA, listB,listA, listB,listA, listB,listA, listB,listA, listB] 13 | wb = Workbook() 14 | ws1 = wb.active # work sheet 15 | ws1.title = "Pyxl" 16 | ft_1 = Font(name='Calibri',color=colors.BLUE, bold=True, size=11,underline='none') 17 | ft_2 = Font(name='Calibri',color=colors.GREEN, bold=True, size=11,underline='none') 18 | ft_3 = Font(name='Calibri',color=colors.RED, bold=True, size=11,underline='none') 19 | ft_4 = Font(name='Calibri',color=colors.BLACK, bold=True, size=11,underline='none') 20 | 21 | for i in range(len(listA)): 22 | for j in range (len(L)): 23 | _ = ws1.cell(column=j+2, row=i+2, value=L[j][i]) 24 | if i==len(listA)-1 : 25 | _ = ws1.cell(column=j+2, row=i+3, value='=SUM('+get_column_letter(j+2)+str(i-len(listA)+2)+':'+ get_column_letter(j+2)+str(i+2)+')') 26 | _.font=ft_1 27 | _ = ws1.cell(column=j+2, row=i+4, value='=average('+get_column_letter(j+2)+str(i-len(listA)+2)+':'+ get_column_letter(j+2)+str(i+2)+')') 28 | _.font=ft_2 29 | _.number_format='#,#0.0' 30 | _ = ws1.cell(column=j+2, row=i+5, value='=max('+get_column_letter(j+2)+str(i-len(listA)+2)+':'+ get_column_letter(j+2)+str(i+2)+')') 31 | _.font=ft_3 32 | # ws1.append([listA[row]]) 33 | 34 | for i, name in enumerate(['Summation', 'Average', 'Maximum']): 35 | _ = ws1.cell(column=1, row=len(listA)+2+i, value=name) 36 | _.font=ft_4 37 | 38 | 39 | 40 | # ft_h = Font(name='Calibri',color=colors.BLUE, bold=True, size=11,underline='double') 41 | # ft_b = Font(name='Calibri',color=colors.RED, bold=True, size=11,underline='single') 42 | # a1 = ws1['A1'] 43 | # b1 = ws1['B1'] 44 | # a1.font = ft_h 45 | # b1.font = ft_h 46 | 47 | # for i in range (2,13): 48 | # a=ws1['A'+str(i)] 49 | # b=ws1['B'+str(i)] 50 | # a.font=ft_b 51 | # b.font=ft_b 52 | 53 | # ws1["A14"]='Summation=' 54 | # ws1["B14"]='=SUM(B3:B13)' 55 | # ws1["C14"]='=SUM(C3:C13)' 56 | 57 | 58 | # ws1["A15"]='Maximum=' 59 | # ws1["B15"]='=max(B3:B13)' 60 | # ws1["C15"]='=max(C3:C13)' 61 | 62 | # # Average 63 | # ws1["A16"]='Average=' 64 | # ws1["C16"]='=average(C3:C13)' 65 | # ws1["B16"]='=average(B3:B13)' 66 | 67 | wb.save('xlfile.xlsx') 68 | -------------------------------------------------------------------------------- /Python Excel 3-1.py: -------------------------------------------------------------------------------- 1 | # See full Toturial at my Youtube Channel(YB TV): https://www.youtube.com/channel/UCvnhhDKv5takEN412dmVW8g/featured 2 | # GitHab Page:https://github.com/yasser64b/ 3 | #Email: big3del@gmail.com 4 | 5 | from openpyxl import Workbook 6 | from openpyxl.chart import BarChart, Reference, Series, LineChart, ScatterChart 7 | from openpyxl.styles import Font, Color, colors 8 | 9 | wb = Workbook() 10 | ws = wb.active 11 | for i in range(10): 12 | ws.append([i]) 13 | 14 | # drawing a graph 15 | values = Reference(ws, min_col=1, min_row=1, max_col=1, max_row=10) 16 | # chart = LineChart() 17 | chart = BarChart() 18 | ws.add_chart(chart, "A15") 19 | chart.title = "Chart" 20 | chart.y_axis.title = 'Size' 21 | chart.x_axis.title = 'Test Number' 22 | chart.add_data(values) 23 | 24 | s1 = chart.series[0] 25 | s1.marker.symbol = "triangle" 26 | 27 | 28 | 29 | wb.save("Chart-1.xlsx") 30 | -------------------------------------------------------------------------------- /Python Excel 3-2.py: -------------------------------------------------------------------------------- 1 | # See full Toturial at my Youtube Channel(YB TV): https://www.youtube.com/channel/UCvnhhDKv5takEN412dmVW8g/featured 2 | # GitHab Page:https://github.com/yasser64b/ 3 | #Email: big3del@gmail.com 4 | 5 | from openpyxl import Workbook # pip install openpyxl 6 | from openpyxl.styles import Font, Color, colors 7 | from openpyxl.utils import get_column_letter 8 | from openpyxl.chart import BarChart, Reference, Series, LineChart, ScatterChart 9 | # see example 1 or 10 | listA=['DistanceA (m)',1,2,3,4,5,6,7,8,8,9,9,1,2,3,4,5,6,7,8,8,9,9,1,2,3,4,5,6,7,8,8,9,9] 11 | listB=['DistanceB (m)',1,2,3,4,5,6,7,8,8,9,9,1,2,3,4,5,6,7,8,8,9,9,1,2,3,4,5,6,7,8,8,9,9] 12 | L=[listA, listB,listA, listB,listA, listB,listA, listB,listA, listB,listA, listB,listA, listB,listA, listB] 13 | wb = Workbook() 14 | ws1 = wb.active # work sheet 15 | ws1.title = "Pyxl" 16 | ft_1 = Font(name='Calibri',color=colors.BLUE, bold=True, size=11,underline='none') 17 | ft_2 = Font(name='Calibri',color=colors.GREEN, bold=True, size=11,underline='none') 18 | ft_3 = Font(name='Calibri',color=colors.RED, bold=True, size=11,underline='none') 19 | ft_4 = Font(name='Calibri',color=colors.BLACK, bold=True, size=11,underline='none') 20 | 21 | for i in range(len(listA)): 22 | for j in range (len(L)): 23 | _ = ws1.cell(column=j+2, row=i+2, value=L[j][i]) 24 | if i==len(listA)-1 : 25 | _ = ws1.cell(column=j+2, row=i+3, value='=SUM('+get_column_letter(j+2)+str(i-len(listA)+2)+':'+ get_column_letter(j+2)+str(i+2)+')') 26 | _.font=ft_1 27 | _ = ws1.cell(column=j+2, row=i+4, value='=average('+get_column_letter(j+2)+str(i-len(listA)+2)+':'+ get_column_letter(j+2)+str(i+2)+')') 28 | _.font=ft_2 29 | _.number_format='#,#0.0' 30 | _ = ws1.cell(column=j+2, row=i+5, value='=max('+get_column_letter(j+2)+str(i-len(listA)+2)+':'+ get_column_letter(j+2)+str(i+2)+')') 31 | _.font=ft_3 32 | # ws1.append([listA[row]]) 33 | 34 | for i, name in enumerate(['Summation', 'Average', 'Maximum']): 35 | _ = ws1.cell(column=1, row=len(listA)+2+i, value=name) 36 | _.font=ft_4 37 | 38 | 39 | # drw graphs 40 | for j in range (len(L)): 41 | values = Reference(ws1, min_col=j+2, min_row=2, max_col=j+2, max_row=1+len(listA)) 42 | chart = LineChart() 43 | chart.title ='Chart-'+str(j+1) 44 | chart.y_axis.title = 'Size' 45 | chart.x_axis.title = 'Number-'+str(j+1) 46 | chart.add_data(values) 47 | if j