def result(): if request.method == 'POST' or request.method == 'GET': engine = sqlite3.connect('csv_test10.db') result = request.form['q'] query = qu_op(result) b = query.split(' ') yr = [] for i in b: if 'year' in i: yr.append(i[5:len(i)]) df = pd.read_sql_query(query, engine) print(df) if df.loc[0, 'graph'] == '2': bar_chart = pygal.Bar(width=800, height=600, legend_at_bottom=True, human_readable=True, background='white', title=df.columns.values[1].capitalize() + ' across months in ' + yr[0], x_title='Months', y_title=df.columns.values[1].capitalize()) for index, row in df.iterrows(): bar_chart.add(row[2], row[1]) final = bar_chart.render_data_uri() #df = df.sort_values('sales',ascending=False) elif df.loc[0, 'graph'] == '1': country_dict = {} wm = World(show_legend=False) wm.title = df.columns.values[2].capitalize( ) + " across Top Countries in " + yr[0] for i in range(len(df)): for code, name in COUNTRIES.items(): if name.lower() == df.iloc[i, 1].lower(): country_dict[code] = df.iloc[i, 2] wm.add("Country:", country_dict) final = wm.render_data_uri() return render_template('result.html', result=final)