I'm trying to be able to delete specific lines from a csv file using the pandas. This is what I have so far:
def delete_from_file():
student_name = input("What is the name of the student? ")
df = pd.read_csv('students.csv', names = ['name', 'phone number', 'class time', 'duration'], index_col=0)
df.drop(student_name)
print(df)
and this is what a sample line from the csv file looks like:
"Carl Henderson,900-122-818,12:15pm,30 mins"
I want to be able to write "Carl Henderson" for the student_name and basically have the whole row removed.
Change your function to
def delete_from_file(student_name):
df = pd.read_csv('students.csv', names = ['name', 'phone number', 'class time', 'duration']).set_index('name')
df=df.drop(student_name)
return df
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments