Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

The practice of reading and writing csv files by python

Shulou Source: shulou.com Published: 2022-06-03 05:47:41 10月03日 Update

Csv introduction

What is csv? Everyone may have heard of it, but I guess few people can give a more comprehensive explanation, so I will make a fool of myself. Csv what I understand is a file that stores data with commas as splits (or tabs).

Rules of csv

1 begins with no space, with a behavior unit.

2 column names may or may not be included, and column names are on the first line of the file.

3 a row of data does not span rows and has no blank lines.

(4) use a half-corner comma (that is,) as a delimiter, and a blank column should also express its existence.

If there are half-width quotation marks (that is, "), replace them with half-width double quotation marks ("), that is, enclose the field value in half-width quotes (that is,").

(6) the operation rules of quotation marks and commas are reciprocal when reading and writing files.

7 Internal code format is unlimited, can be ASCII, Unicode or other.

8 Special characters are not supported

Python csv

Csv module is built into python, which can be used directly by import csv.

The common methods are as follows:

Writer 、 DictWriter 、 reader 、 DictReader

There should be no need for me to explain. If you don't know, check the meaning of English for yourself. Those with dict are read and written through a dictionary.

Code actual combat

For how to obtain the source code, please watch the video.

Tags: Halves quotes files commas lines data methods rules storage interpretation practice special no code content internal code delimiters tabs units dictionaries Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MariaDB macOS Shulou Tech Info Microsoft