Want to make a list of words using python where the student received a 0 for the word in that column -
relatively new python, , programming in general, want take student assessment list , iterate through each row print list includes student name , each word (column name) student missed (recorded 0).
table looks this:
name - id - again - - - away - best - every student1 - 13 - 1 - 0 - 0 - 1 - 0 - 0 student2 - 14 - 1 - 1 - 1 - 0 - 0 - 1 student3 - 15 - 0 - 0 - 0 - 1 - 1 - 1
want write this:
for row in dataframe: if row == 0: print student name +':' + column name
output be:
student 1: all, always, best, every student 2: away, best student 3: again, always, away
i've got several hundred students , love have list showing words each student needs practice. appreciated. thanks!
assuming table in pandas dataframe (you should able import using pd.read_csv
or pd.read_csv
:
import pandas pd df = pd.dataframe([['student1',13,1,0,0,1,0,0], ['student2',14,1,1,1,0,0,1], ['student3',15,0,0,0,1,1,1]], columns = ['name','id','again','all','always','away','best','every']) df['wordlist'] = df.apply(lambda row: ', '.join(df.columns[row == 1]),1) line in df.name + ': ' + df.wordlist: print (line) student1: again, away student2: again, all, always, every student3: away, best, every
Comments
Post a Comment