Last active
December 6, 2018 10:28
-
-
Save Deepayan137/7903e83ef23754cb8a3dad9882453af8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from collections import defaultdict | |
import pdb | |
import numpy as np | |
def row(dict_ques): | |
def dosomething(marks): | |
marks = list(marks) | |
total = min(np.sum(marks), 304) | |
return total | |
return dosomething(marks) | |
if __name__ == '__main__': | |
keys = set() | |
_d = defaultdict(lambda: defaultdict(int)) | |
_ids = set() | |
df = pd.read_csv('~/grades.csv') | |
for i, row in df.iterrows(): | |
_id = row['student'] | |
marks = row['marks'] | |
question = row['question'] | |
keys.add(question) | |
_d[_id][question] = marks | |
_ids.add(_id) | |
sorted_keys = sorted(list(keys)) | |
entries = [] | |
header = ['id'] + sorted_keys | |
for _id in _ids: | |
marks = [_d[_id][q] for q in keys] | |
entry = [_id] + marks | |
entries.append(entry) | |
print(entries) | |
df = pd.DataFrame(entries, columns=header) | |
df.to_csv('output.csv') | |
print(df.head()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment