Skip to content

Instantly share code, notes, and snippets.

@cigrainger
Last active December 31, 2015 08:09
Show Gist options
  • Save cigrainger/7958700 to your computer and use it in GitHub Desktop.
Save cigrainger/7958700 to your computer and use it in GitHub Desktop.
import pandas as pd
students = pd.read_csv('students.csv')
def newstudent(x):
newname = raw_input("What is the student's name? ")
newemail = raw_input("What is the student's email address? ")
newrow = [{'name':newname,'email':newemail}]
df = x.append(newrow, ignore_index=True)
return df
def addstudent(x):
newdf = newstudent(x)
again = raw_input("Do you want to add another student? y/n? ")
if again == 'y':
addstudent(newdf)
elif again == 'n':
newdf.to_csv('students.csv', index=False)
return 'Done.'
else:
newdf.to_csv('students.csv', index=False)
return 'Prompt was y/n. Saving progress and quitting.'
addstudent(students)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment