Bhavesh R

Bhavesh R

  • NA
  • 15
  • 3.7k

Return my df from panddf and pass it as argument to graphview function

May 25 2021 4:02 PM
I want my dataframe to be passed into the graphview function..Am trying to get values from df and pass to the graphview function..Can anyone help me with this??
 
from django.http import JsonResponse
from django.shortcuts import render
from board.models import userboard
from.utils import get_plot
import pandas as pd
from sqlalchemy import create_engine
def graphview(request):
qs =userboard.obects.all()
x=[x.Month for x in qs]
y=[y.Bp_Values for y in qs]
chart = get_plot(x,y)
return render(request, 'piechart.html' ,{'chart':chart})
def panddf(request):
username = None
if request.user.is_authenticated:
username = request.user.username
print(username) engine=create_engine('postgresql+psycopg2://postgres:#24May@2002@localhost/bhavesh')
df = pd.read_sql_query('SELECT * FROM public."board_userboard"',con=engine)
filt = (df['User_name'] == username)
print(df[filt])
df1 = (df[filt])
return render(request, 'abc.html')