Get the App
SLTechnology News&Howtos  ›  Development  › 

How does Python delete the content in csv

Shulou Source: shulou.com Published: 2022-05-31 17:45:53 09月26日 Update

This article mainly introduces the relevant knowledge of "how Python deletes the content in csv". The editor shows you the operation process through an actual case. The method of operation is simple and fast, and it is practical. I hope that this article "how to delete the content of csv in Python" can help you solve the problem.

Description

1. Use the drop function to delete rows or columns of data in the file.

Example

2. You can delete certain lines, delete rows (a range), and save the data back to the csv file.

Suppose the name of the column we want to delete is' audience ID',' score':

Df=df.drop (['audience ID',' score'], axis=1)

The specified column can be deleted

Delete a few lines

Df.drop ([1mem2]) # Delete the entire row of data of 2 rows of 1meme

Delete a row (a range)

# Delete a line (range) df.drop (df.index [3:6], inplace=True)

Re-save the data to the csv file

# if you want to save a new csv file, what does index=False,encoding= ("data_new.csv", index=False,encoding= "utf-8") python mean? Python is a cross-platform, interpretive, compiled, interactive and object-oriented scripting language that was originally designed to write automated scripts. as versions are constantly updated and new features are added, Python is often used to develop independent and large projects.

This is the end of the introduction to "how Python deletes the content in csv". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Content data file knowledge scope script industry audience project update score different practical continuous interactive function name example practicality actual Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Microsoft OPPO Reno macOS vpn