def getSexGeneral(): global ageSexe04, usaData df = pd.DataFrame(index=['Male', 'Female'], columns=['Morocco', 'Usa'], data=[[0, 0], [0, 0]]) SexeMar = [ ageSexe04[disType].df[['Masculin', 'Féminin']] for disType in ageSexe04.keys() ] sumUsa = 0 usefulDfs = toolz.dfSelector( toolz.dfSelector(toolz.dfSelector(usaData.dfsArray, 'index', ['SEX']), 'year', ['16']), 'difficulty', ['self-care ', 'vision ', 'hearing ', 'cognitive ', 'ambulatory ']) for tmpExtDf in usefulDfs: for option in ['Male', 'Female']: df.loc[option]['Usa'] += tmpExtDf['dataFrame'].loc[option].sum() for tmpDf in SexeMar: for option in ['Masculin', 'Féminin']: if option == 'Masculin': df.loc['Male']['Morocco'] += tmpDf[option].sum() elif option == 'Féminin': df.loc['Female']['Morocco'] += tmpDf[option].sum() return df
def updateFigWorkExp(states, years): traces = [] for year in years: selectedExtendedDfs = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['WORK EXPERIENCE']), 'state', states), 'year', [year]) df = dfs_sum([df['dataFrame'] for df in selectedExtendedDfs]) traces.append( go.Bar(x=df.index.tolist(), y=df.iloc[:, 0].tolist(), name="20" + year)) return {'data': traces, 'layout': {'title': "WORK EXPERIENCE".title()}}
def getDisTypeGeneral(): global ageSexe04, usaData df = pd.DataFrame(index=[disType for disType in ageSexe04.keys()], columns=['Morocco', 'Usa']) sumMar = pd.Series(index=[disType for disType in ageSexe04.keys()], data=[ ageSexe04[disType].df['Ensemble'].sum() for disType in ageSexe04.keys() ]).sum() for disType in ageSexe04.keys(): df.loc[disType, 'Morocco'] = (ageSexe04[disType].df['Ensemble'].sum()) / sumMar sumUsa = 0 usefulDfs = toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'difficulty', [ 'independent living ', 'self-care ', 'vision ', 'hearing ', 'cognitive ', 'ambulatory ' ]), 'year', ['16']) for tmpDf in usefulDfs: sumUsa += tmpDf['dataFrame'].sum().sum() convDict = { "Sensoriel": toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'difficulty', ['vision ', 'hearing ']), 'year', ['16']), "Moteur": toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'difficulty', ['independent living ', 'self-care ']), 'year', ['16']), "Chronique": toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'difficulty', ['ambulatory ']), 'year', ['16']), "Mental": toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'difficulty', ['cognitive ']), 'year', ['16']) } for disType in df.index.tolist(): tmpSum = 0 for tmpExtDf in convDict[disType]: tmpSum += tmpExtDf['dataFrame'].sum().sum() df.loc[disType, 'Usa'] = tmpSum / sumUsa return df
def updateFigEmplStatus(states, years): if len(years) > 1: selectedExtendedDfsForYear1 = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['EMPLOYMENT SECTOR']), 'state', states), 'year', [years[0]]) dfYear1 = dfs_sum( [df['dataFrame'] for df in selectedExtendedDfsForYear1]) selectedExtendedDfsForYear2 = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['EMPLOYMENT SECTOR']), 'state', states), 'year', [years[1]]) dfYear2 = dfs_sum( [df['dataFrame'] for df in selectedExtendedDfsForYear2]) trace = go.Sunburst( ids=["20" + year for year in years] + [ "20" + year + " - " + status for year in years for status in dfYear1.columns.tolist() ], labels=["20" + year for year in years] + [status for status in dfYear1.columns.tolist()] * 2, parents=["" for i in range(len(years))] + list( chain.from_iterable( ("20" + year, "20" + year) for year in years)), values=[dfYear1.iloc[0, :].sum(), dfYear2.iloc[0, :].sum()] + [ dfYear1.iloc[0, 0], dfYear1.iloc[0, 1], dfYear2.iloc[0, 0], dfYear2.iloc[0, 1] ], branchvalues="total", ) return { 'data': [trace], 'layout': { 'title': "EMPLOYMENT STATUS".title() } } else: selectedExtendedDfs = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['EMPLOYMENT SECTOR']), 'state', states), 'year', [years[0]]) df = dfs_sum([df['dataFrame'] for df in selectedExtendedDfs]) trace = go.Pie(labels=df.columns.tolist(), values=df.iloc[0].tolist()) return { 'data': [trace], 'layout': { 'title': "EMPLOYMENT STATUS".title() } }
def updateFigEmplStatus(states, years): global layout, my_colors, my_line_colors my_colors1 = copy.deepcopy(my_colors).extend(my_line_colors) layout1 = copy.deepcopy(layout) layout1['title'] = "EMPLOYMENT STATUS".title() if len(years) > 1: selectedExtendedDfsForYear1 = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['EMPLOYMENT SECTOR']), 'state', states), 'year', [years[0]]) dfYear1 = dfs_sum( [df['dataFrame'] for df in selectedExtendedDfsForYear1]) selectedExtendedDfsForYear2 = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['EMPLOYMENT SECTOR']), 'state', states), 'year', [years[1]]) dfYear2 = dfs_sum( [df['dataFrame'] for df in selectedExtendedDfsForYear2]) trace = go.Sunburst( ids=["20" + year for year in years] + [ "20" + year + " - " + status for year in years for status in dfYear1.columns.tolist() ], labels=["20" + year for year in years] + [status for status in dfYear1.columns.tolist()] * 2, parents=["" for i in range(len(years))] + list( chain.from_iterable( ("20" + year, "20" + year) for year in years)), values=[dfYear1.iloc[0, :].sum(), dfYear2.iloc[0, :].sum()] + [ dfYear1.iloc[0, 0], dfYear1.iloc[0, 1], dfYear2.iloc[0, 0], dfYear2.iloc[0, 1] ], branchvalues="total", marker=dict(colors=my_colors, autocolorscale=True)) return {'data': [trace], 'layout': layout1} else: selectedExtendedDfs = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['EMPLOYMENT SECTOR']), 'state', states), 'year', [years[0]]) df = dfs_sum([df['dataFrame'] for df in selectedExtendedDfs]) trace = go.Pie(labels=df.columns.tolist(), values=df.iloc[0].tolist(), marker_colors=my_colors, hole=.3, opacity=0.7) return {'data': [trace], 'layout': layout1}
def updateFigWorkExp(states, years): global layout, my_colors layout1 = copy.deepcopy(layout) layout1['title'] = "WORK EXPERIENCE".title() traces = [] for year in years: selectedExtendedDfs = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['WORK EXPERIENCE']), 'state', states), 'year', [year]) df = dfs_sum([df['dataFrame'] for df in selectedExtendedDfs]) traces.append( go.Scatterpolar(r=df.iloc[:, 0], theta=df.index, fill='toself', name=df.columns.tolist()[0] + ' (20' + year + ')', line=dict(color=my_colors[years.index(year)]))) layout1['polar'] = dict(radialaxis=dict(visible=True)) layout1['showlegend'] = True return {'data': traces, 'layout': layout1}
def updateFigAgeDisNumber(states, ageCateg, year): global layout, my_colors, my_line_colors layout1 = copy.deepcopy(layout) layout1['title'] = "Prevalence BY NUMBER OF DISABILITIES".title() if len(year) > 1: selectedExtendedDfsForYear1 = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['AGE']), 'state', states), "columns", ["NUMBER OF DISABILITIES"]), 'year', [year[0]]) selectedExtendedDfsForYear2 = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['AGE']), 'state', states), "columns", ["NUMBER OF DISABILITIES"]), 'year', [year[1]]) dfYear1 = dfs_sum( [df['dataFrame'] for df in selectedExtendedDfsForYear1]) dfYear2 = dfs_sum( [df['dataFrame'] for df in selectedExtendedDfsForYear2]) fig = make_subplots(rows=1, cols=2, subplot_titles=("20" + str(year[0]), "20" + str(year[1]))) fig.add_trace(go.Bar( x=[index[:-1] for index in dfYear1.index.tolist()], y=dfYear1.iloc[:, 0].tolist(), name=dfYear1.columns.tolist()[0].title(), marker_color=my_colors[0], marker_line_color=my_line_colors[0], marker_line_width=1.5, opacity=0.6), row=1, col=1) fig.add_trace(go.Bar( x=[index[:-1] for index in dfYear1.index.tolist()], y=dfYear1.iloc[:, 1].tolist(), name=dfYear1.columns.tolist()[1].title(), marker_color=my_colors[1], marker_line_color=my_line_colors[1], marker_line_width=1.5, opacity=0.6), row=1, col=1) fig.add_trace(go.Bar( x=[index[:-1] for index in dfYear2.index.tolist()], y=dfYear2.iloc[:, 0].tolist(), name=dfYear2.columns.tolist()[0].title(), marker_color=my_colors[0], marker_line_color=my_line_colors[0], marker_line_width=1.5, opacity=0.6, showlegend=False), row=1, col=2) fig.add_trace(go.Bar( x=[index[:-1] for index in dfYear2.index.tolist()], y=dfYear2.iloc[:, 1].tolist(), name=dfYear2.columns.tolist()[1].title(), marker_color=my_colors[1], marker_line_color=my_line_colors[1], marker_line_width=1.5, opacity=0.6, showlegend=False), row=1, col=2) fig.update_layout(barmode='stack') fig.update_layout(autosize=True) fig.update_layout(margin=dict(l=30, r=30, b=20, t=40)) fig.update_layout(hovermode="closest") fig.update_layout(plot_bgcolor="#F9F9F9") fig.update_layout(paper_bgcolor="#F9F9F9") fig.update_layout(legend=dict(font=dict(size=10), orientation="h")) fig.update_layout(yaxis=go.YAxis(showticklabels=False)) fig.update_layout( title=dict(text='Prevalence By Number Of Disabilities', x=0.5, xanchor='center')) return fig else: selectedExtendedDfs = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['AGE']), 'state', states), "columns", ["NUMBER OF DISABILITIES"]), 'year', [year[0]]) df = dfs_sum([df['dataFrame'] for df in selectedExtendedDfs]) trace1 = go.Bar(x=[index[:-1] for index in df.index.tolist()], y=df.iloc[:, 0].tolist(), name=df.columns.tolist()[0].title(), marker_color=my_colors[0], marker_line_color=my_line_colors[0], marker_line_width=1.5, opacity=0.6) trace2 = go.Bar(x=[index[:-1] for index in df.index.tolist()], y=df.iloc[:, 1].tolist(), name=df.columns.tolist()[1].title(), marker_color=my_colors[1], marker_line_color=my_line_colors[1], marker_line_width=1.5, opacity=0.6) return {'data': [trace1, trace2], 'layout': layout1}
def updateFigHealthIns(states, ageCateg, year): global layout, my_colors, my_line_colors layout1 = copy.deepcopy(layout) layout1['title'] = "Health Insurance Coverage".title() if len(year) > 1: selectedExtendedDfsForYear1 = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['AGE']), 'state', states), "columns", ["POPULATION"]), 'year', [year[0]]) selectedExtendedDfsForYear2 = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['AGE']), 'state', states), "columns", ["POPULATION"]), 'year', [year[1]]) dfYear1 = dfs_sum( [df['dataFrame'] for df in selectedExtendedDfsForYear1]) dfYear2 = dfs_sum( [df['dataFrame'] for df in selectedExtendedDfsForYear2]) trace1 = go.Bar(x=[index[:-1] for index in dfYear1.index.tolist()], y=dfYear1.iloc[:, 0].tolist(), name="20" + year[0], marker_color=my_colors[0], marker_line_color=my_line_colors[0], marker_line_width=1.5, opacity=0.6) trace2 = go.Bar(x=[index[:-1] for index in dfYear2.index.tolist()], y=dfYear2.iloc[:, 0].tolist(), name="20" + year[1], marker_color=my_colors[1], marker_line_color=my_line_colors[1], marker_line_width=1.5, opacity=0.6) return {'data': [trace1, trace2], 'layout': layout1} else: selectedExtendedDfs = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['AGE']), 'state', states), "columns", ["POPULATION"]), 'year', [year[0]]) df = dfs_sum([df['dataFrame'] for df in selectedExtendedDfs]) trace = go.Bar(x=[index[:-1] for index in df.index.tolist()], y=df.iloc[:, 0].tolist(), marker_color=my_colors[0], marker_line_color=my_line_colors[0], marker_line_width=1.5, opacity=0.6) return {'data': [trace], 'layout': layout1}
def updateFigAge(ageCateg, states, sex, difTypes, year): global layout, my_colors, my_line_colors layout1 = copy.deepcopy(layout) layout1['title'] = "PREVALENCE BY AGE".title() if len(year) == 1: selectedExtendedDfs = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['SEX']), 'state', states), 'difficulty', difTypes), 'year', year) df = dfs_sum([df['dataFrame'] for df in selectedExtendedDfs ])[toolz.getAgeOptions(usaData.dfsArray, ageCateg)] if len(sex) == 2: trace1 = go.Bar(x=df.columns.tolist(), y=df.loc["Male"].tolist(), name='Male', marker_color=my_colors[0], marker_line_color=my_line_colors[0], marker_line_width=1.5, opacity=0.6) trace2 = go.Bar(x=df.columns.tolist(), y=df.loc["Female"].tolist(), name='Female', marker_color=my_colors[1], marker_line_color=my_line_colors[1], marker_line_width=1.5, opacity=0.6) return {'data': [trace1, trace2], 'layout': layout1} else: trace = go.Bar(x=df.columns.tolist(), y=df.loc[sex[0].title()].tolist(), name=sex[0].title(), marker_color=my_colors[0], marker_line_color=my_line_colors[0], marker_line_width=1.5, opacity=0.6) return {'data': [trace], 'layout': layout1} else: selectedExtendedDfsForYear1 = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['SEX']), 'state', states), 'difficulty', difTypes), 'year', [year[0]]) selectedExtendedDfsForYear2 = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['SEX']), 'state', states), 'difficulty', difTypes), 'year', [year[1]]) dfYear1 = dfs_sum([ df['dataFrame'] for df in selectedExtendedDfsForYear1 ])[toolz.getAgeOptions(usaData.dfsArray, ageCateg)] dfYear2 = dfs_sum([ df['dataFrame'] for df in selectedExtendedDfsForYear2 ])[toolz.getAgeOptions(usaData.dfsArray, ageCateg)] if len(sex) == 2: trace1 = go.Bar(x=dfYear1.columns.tolist(), y=dfYear1.loc["Male"].tolist(), name='Male (20' + year[0] + ")", width=0.15, marker_color=my_colors[0], marker_line_color=my_line_colors[0], marker_line_width=1.5, opacity=0.6) trace2 = go.Bar(x=dfYear1.columns.tolist(), y=dfYear1.loc["Female"].tolist(), name='Female (20' + year[0] + ")", width=0.15, marker_color=my_colors[1], marker_line_color=my_line_colors[1], marker_line_width=1.5, opacity=0.6) trace3 = go.Bar(x=dfYear1.columns.tolist(), y=dfYear2.loc["Male"].tolist(), name='Male (20' + year[1] + ")", width=0.15, marker_color=my_colors[0], marker_line_color=my_line_colors[0], marker_line_width=1.5, opacity=0.6) trace4 = go.Bar(x=dfYear1.columns.tolist(), y=dfYear2.loc["Female"].tolist(), name='Female (20' + year[1] + ")", width=0.15, marker_color=my_colors[1], marker_line_color=my_line_colors[1], marker_line_width=1.5, opacity=0.6) return { 'data': [trace1, trace2, trace3, trace4], 'layout': layout1 } else: traces = [ go.Bar(x=dfYear1.columns.tolist(), y=dfYear1.loc[sex[0].title()].tolist(), name=sex[0].title()), go.Bar(x=dfYear1.columns.tolist(), y=dfYear2.loc[sex[0].title()].tolist(), name=sex[0].title()) ] traces = trace = [ go.Bar(name="20" + year[0], x=dfYear1.columns.tolist(), y=dfYear1.loc[sex[0].title()].tolist(), marker_color=my_colors[0], marker_line_color=my_line_colors[0], marker_line_width=1.5, opacity=0.6), go.Bar(name="20" + year[1], x=dfYear1.columns.tolist(), y=dfYear2.loc[sex[0].title()], marker_color=my_colors[1], marker_line_color=my_line_colors[1], marker_line_width=1.5, opacity=0.6) ] return {'data': traces, 'layout': layout1}
def updateFigAgeDisNumber(states, ageCateg, year): if len(year) > 1: selectedExtendedDfsForYear1 = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['AGE']), 'state', states), "columns", ["NUMBER OF DISABILITIES"]), 'year', [year[0]]) selectedExtendedDfsForYear2 = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['AGE']), 'state', states), "columns", ["NUMBER OF DISABILITIES"]), 'year', [year[1]]) dfYear1 = dfs_sum( [df['dataFrame'] for df in selectedExtendedDfsForYear1]) dfYear2 = dfs_sum( [df['dataFrame'] for df in selectedExtendedDfsForYear2]) fig = make_subplots(rows=1, cols=2, subplot_titles=("20" + str(year[0]), "20" + str(year[1]))) fig.add_trace(go.Bar( x=[index[:-1] for index in dfYear1.index.tolist()], y=dfYear1.iloc[:, 0].tolist(), name=dfYear1.columns.tolist()[0].title()), row=1, col=1) fig.add_trace(go.Bar( x=[index[:-1] for index in dfYear1.index.tolist()], y=dfYear1.iloc[:, 1].tolist(), name=dfYear1.columns.tolist()[1].title()), row=1, col=1) fig.add_trace(go.Bar( x=[index[:-1] for index in dfYear1.index.tolist()], y=dfYear2.iloc[:, 0].tolist(), name=dfYear2.columns.tolist()[0].title()), row=1, col=2) fig.add_trace(go.Bar( x=[index[:-1] for index in dfYear1.index.tolist()], y=dfYear2.iloc[:, 1].tolist(), name=dfYear2.columns.tolist()[1].title()), row=1, col=2) return fig else: selectedExtendedDfs = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['AGE']), 'state', states), "columns", ["NUMBER OF DISABILITIES"]) df = dfs_sum([df['dataFrame'] for df in selectedExtendedDfs]) trace1 = go.Bar(x=[index[:-1] for index in df.index.tolist()], y=df.iloc[:, 0].tolist(), name=df.columns.tolist()[0].title()) trace2 = go.Bar(x=[index[:-1] for index in df.index.tolist()], y=df.iloc[:, 1].tolist(), name=df.columns.tolist()[1].title()) return { 'data': [trace1, trace2], 'layout': { 'title': "AGE BY NUMBER OF DISABILITIES".title() } }
def updateFigHealthIns(states, ageCateg, year): if len(year) > 1: selectedExtendedDfsForYear1 = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['AGE']), 'state', states), "columns", ["POPULATION"]), 'year', [year[0]]) selectedExtendedDfsForYear2 = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['AGE']), 'state', states), "columns", ["POPULATION"]), 'year', [year[1]]) dfYear1 = dfs_sum( [df['dataFrame'] for df in selectedExtendedDfsForYear1]) dfYear2 = dfs_sum( [df['dataFrame'] for df in selectedExtendedDfsForYear2]) trace1 = go.Bar(x=[index[:-1] for index in dfYear1.index.tolist()], y=dfYear1.iloc[:, 0].tolist(), name="20" + year[0]) trace2 = go.Bar(x=[index[:-1] for index in dfYear2.index.tolist()], y=dfYear2.iloc[:, 0].tolist(), name="20" + year[1]) return { 'data': [trace1, trace2], 'layout': { 'title': "PREVALENCE OF INSURED DISABLED PEOPLE".title() } } else: selectedExtendedDfs = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['AGE']), 'state', states), "columns", ["POPULATION"]), 'year', [year[0]]) df = dfs_sum([df['dataFrame'] for df in selectedExtendedDfs]) trace = go.Bar(x=[index[:-1] for index in df.index.tolist()], y=df.iloc[:, 0].tolist()) return { 'data': [trace], 'layout': { 'title': "PREVALENCE OF INSURED DISABLED PEOPLE".title() } }
def updateFigAge(ageCateg, states, sex, difTypes, year): if len(year) == 1: selectedExtendedDfs = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['SEX']), 'state', states), 'difficulty', difTypes), 'year', year) df = dfs_sum([df['dataFrame'] for df in selectedExtendedDfs ])[toolz.getAgeOptions(usaData.dfsArray, ageCateg)] if len(sex) == 2: trace1 = go.Bar(x=df.columns.tolist(), y=df.loc["Male"].tolist(), name='Male') trace2 = go.Bar(x=df.columns.tolist(), y=df.loc["Female"].tolist(), name='Female') return { 'data': [trace1, trace2], 'layout': { 'title': "PREVALENCE BY AGE".title() } } else: trace = go.Bar(x=df.columns.tolist(), y=df.loc[sex[0].title()].tolist(), name=sex[0].title()) return { 'data': [trace], 'layout': { 'title': "PREVALENCE BY AGE".title() } } else: selectedExtendedDfsForYear1 = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['SEX']), 'state', states), 'difficulty', difTypes), 'year', [year[0]]) selectedExtendedDfsForYear2 = toolz.dfSelector( toolz.dfSelector( toolz.dfSelector( toolz.dfSelector(usaData.dfsArray, 'index', ['SEX']), 'state', states), 'difficulty', difTypes), 'year', [year[1]]) dfYear1 = dfs_sum([ df['dataFrame'] for df in selectedExtendedDfsForYear1 ])[toolz.getAgeOptions(usaData.dfsArray, ageCateg)] dfYear2 = dfs_sum([ df['dataFrame'] for df in selectedExtendedDfsForYear2 ])[toolz.getAgeOptions(usaData.dfsArray, ageCateg)] if len(sex) == 2: trace1 = go.Bar(x=dfYear1.columns.tolist(), y=dfYear1.loc["Male"].tolist(), name='Male (20' + year[0] + ")", width=0.15) trace2 = go.Bar(x=dfYear1.columns.tolist(), y=dfYear1.loc["Female"].tolist(), name='Female (20' + year[0] + ")", width=0.15) trace3 = go.Bar(x=dfYear1.columns.tolist(), y=dfYear2.loc["Male"].tolist(), name='Male (20' + year[1] + ")", width=0.15) trace4 = go.Bar(x=dfYear1.columns.tolist(), y=dfYear2.loc["Female"].tolist(), name='Female (20' + year[1] + ")", width=0.15) return { 'data': [trace1, trace2, trace3, trace4], 'layout': { 'title': "PREVALENCE BY AGE".title(), } } else: trace = go.Bar(x=df.columns.tolist(), y=df.loc[sex[0].title()].tolist(), name=sex[0].title()) return { 'data': [trace], 'layout': { 'title': "PREVALENCE BY AGE".title() } }