summaryrefslogtreecommitdiff
path: root/yaksh
diff options
context:
space:
mode:
authoradityacp2021-02-11 11:04:59 +0530
committeradityacp2021-02-11 11:04:59 +0530
commited50666eceb10b7c8cfa1352ffde2c1025f3aa9a (patch)
tree796cc1ecec9f841920e79903f48c16017defa17f /yaksh
parent8c1c1f6c8b1de16fba5f93e58a0cd3cb751e02d7 (diff)
downloadonline_test-ed50666eceb10b7c8cfa1352ffde2c1025f3aa9a.tar.gz
online_test-ed50666eceb10b7c8cfa1352ffde2c1025f3aa9a.tar.bz2
online_test-ed50666eceb10b7c8cfa1352ffde2c1025f3aa9a.zip
Fix issue in pandas dataframe where key is not available
Diffstat (limited to 'yaksh')
-rw-r--r--yaksh/models.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/yaksh/models.py b/yaksh/models.py
index 5934ae2..16800fe 100644
--- a/yaksh/models.py
+++ b/yaksh/models.py
@@ -2173,11 +2173,12 @@ class AnswerPaperManager(models.Manager):
answerpaper__id__in=answerpaper_ids
).values("question_id", "answerpaper__id")
df = pd.DataFrame(answers)
- answerpapers = df.groupby("answerpaper__id")
- question_attempted = {}
- for ap in answerpapers:
- question_attempted[ap[0]] = len(ap[1]["question_id"].unique())
- return question_attempted
+ if not df.empty and "answerpaper__id" in df.columns:
+ answerpapers = df.groupby("answerpaper__id")
+ question_attempted = {}
+ for ap in answerpapers:
+ question_attempted[ap[0]] = len(ap[1]["question_id"].unique())
+ return question_attempted
###############################################################################