summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradityacp2020-08-17 13:57:18 +0530
committeradityacp2020-08-17 13:57:18 +0530
commit41e2f21fe7559cf205b1739cfa4967563f1eb699 (patch)
treecd82e601e52333aaf1d1cec4377c351ef335e17b
parentd83c3d455659369ee989746cf91a08feddd2975e (diff)
downloadworkshop_booking-41e2f21fe7559cf205b1739cfa4967563f1eb699.tar.gz
workshop_booking-41e2f21fe7559cf205b1739cfa4967563f1eb699.tar.bz2
workshop_booking-41e2f21fe7559cf205b1739cfa4967563f1eb699.zip
Convert the django orm values to list for pandas
-rw-r--r--statistics_app/views.py8
-rw-r--r--workshop_app/models.py4
2 files changed, 7 insertions, 5 deletions
diff --git a/statistics_app/views.py b/statistics_app/views.py
index 3c9fcae..3e45495 100644
--- a/statistics_app/views.py
+++ b/statistics_app/views.py
@@ -75,13 +75,15 @@ def workshop_public_stats(request):
"instructor__last_name", "coordinator__profile__state",
"date", "status"
)
- df = pd.DataFrame(data)
+ df = pd.DataFrame(list(data))
if not df.empty:
df.status.replace(
[0, 1, 2], ['Pending', 'Success', 'Reject'], inplace=True
)
- codes, states = list(zip(*states))
- df.coordinator__profile__state.replace(codes, states, inplace=True)
+ codes, states_map = list(zip(*states))
+ df.coordinator__profile__state.replace(
+ codes, states_map, inplace=True
+ )
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = f'attachment; filename=statistics.csv'
output_file = df.to_csv(response, index=False)
diff --git a/workshop_app/models.py b/workshop_app/models.py
index 48856fd..976a318 100644
--- a/workshop_app/models.py
+++ b/workshop_app/models.py
@@ -162,7 +162,7 @@ class WorkshopManager(models.Manager):
def get_workshops_by_state(self, workshops):
w = workshops.values_list("coordinator__profile__state", flat=True)
states_map = dict(states)
- df = pd.DataFrame(w)
+ df = pd.DataFrame(list(w))
data_states, data_counts = [], []
if not df.empty:
grouped_data = df.value_counts().to_dict()
@@ -174,7 +174,7 @@ class WorkshopManager(models.Manager):
def get_workshops_by_type(self, workshops):
w = workshops.values_list("workshop_type__name", flat=True)
- df = pd.DataFrame(w)
+ df = pd.DataFrame(list(w))
data_wstypes, data_counts = [], []
if not df.empty:
grouped_data = df.value_counts().to_dict()