How can I remove a line from a csv file using pandas?

user12380394

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.

BENY

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.

edited at
0

Comments

0 comments
Login to comment

Related

How can I remove extra whitespace from strings when parsing a csv file in Pandas?

How can I insert data from a CSV file into a dataframe using pandas.read_csv?

How do you remove sections from a csv file using pandas?

How can I return a record from a CSV file using the byte position of line?

How can I remove header from csv or txt file?

How can I write each process from multiprocessing to a separate csv file using pandas?

How do I read from a csv file using pandas in python?

How can I select a record line from a file using SED

How can I filter keywords from a csv file using Python

How can I remove the 1st line of a CSV file which is in AWS S3 through

How can I remove a specific line from a file only if there are other lines in the file?

How can I remove characters from a line in a text file without renaming the file?

How to remove comma from end of line in CSV file while exporting using C#

How can I process a large CSV file line by line?

how to remove both first and last line of csv file using sed

How to remove a line from csv file if it contains a specific word

How can I remove the first element from a list with pandas.read_csv?

How can I remove the first line of a text file using bash/sed script?

How can I get the csv file line content and save it to the database using NiFi processors?

How can I get the first line of a csv file in JavaScript (node) synchronously and without using promises?

How can I remove a row from csv file with python where a value of any column is missing

How can i output more than one identical line from a csv file in python

Is there a reason I can't write to, and later read from the same csv file using pandas?

Remove Semicolons as Line Delimiters Reading csv-file Using pandas.read_csv

How can I read and remove meta (exif) data from my photos using the command line?

How can I remove a specific character from multi line string using regex in python

How can I remove text on the last line of a file?

How can I remove the first line of a file with sed?

How can I remove the first whitespace of every line of a file?