Methods for Python to read and extract data from CSV files

Time:2022-6-19
catalogue

Data saved in CSV file

Methods for Python to read and extract data from CSV files

 

1. read data from CSV file

Whether the parameter header=none exists

(1) No header=none — directly take the first row in the CSV table as the header

#Read data

The print result is:

Methods for Python to read and extract data from CSV files

(2) With header=none — automatically add the first row as the header

#Read data

The print result is:

Methods for Python to read and extract data from CSV files

 

2. data cutting

(the header=none is not written here according to the format of the CSV table.)

(1) Get all the columns and store them in an array

#Read data

(2) Get the data of the specified column and store it in an array
Method 1: get data from CSV file, data[] — the dimension of data needs to be considered

#Read data

Method II: usecols=[] — number of columns obtained by direct write

import pandas as pd

Method III: iloc[] — the essence is slicing

import pandas as pd

This is the end of this article about Python’s methods of reading data from CSV files and extracting data. For more information about reading data from Python CSV files, please search previous articles on developeppaper or continue to browse the following articles. I hope you will support developeppaper in the future!