Want to make a list of words using python where the student received a 0 for the word in that column
Question: Relatively new to python, and programming in general, but want to take a
student assessment list and iterate through each row then print a list that
includes the student name and each word (column name) that the student missed
(recorded as 0).

table looks something like this:

    
    
    Name      -  ID - again - all - always - 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 to write something like this:

    
    
    for row in dataframe:
      if row == 0:
        print student name +':' + column name 
    

Output would be:

    
    
    student 1: all, always, best, every 
    student 2: away, best
    student 3: again, always, away
    

I've got several hundred students and would love to just have a list showing
which words each student needs to practice. Any help is much appreciated.
Thanks!


Answer: Assuming your table is in a Pandas dataframe (you should be able to import it
using `pd.read_csv` or `pd.read_csv`:

    
    
    import pandas as 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)
    for line in df.Name +  ': ' + df.wordlist:
       print (line)
    
    student1: again, away
    student2: again, all, always, every
    student3: away, best, every
    

