Python syntax 1 minute: read CSV file

Preface

The text and pictures in this article are from the Internet and are for learning and communication purposes only, and do not have any commercial use. If you have any questions, please contact us for processing.

PS: If you need Python learning materials, you can click on the link below to get it by yourself

Python free learning materials, codes and exchange answers click to join


Introduction

The csv file is a very common data source file. Generally, when we analyze small-scale data, most of us will directly read the .csv file.

The full name of the csv file is "Comma-Separated Values", which is interpreted as comma-separated values.

When we want to read a CSV file into Python, one of the most commonly used methods is to use pd.read_csv() to read the CSV data as a DataFrame.

Environment introduction

  • System environment: Windows 10
  • Python version: Python 3.7
  • Essential library: pandas

Core sentence


import pandas as pd
pd.read_csv('/文件路径')

Code sample

Assuming that there is a .csv file named "orange_cat" in our computer, the file is saved in the following path:
C:/Users/osc/Desktop/
We can use the following statement to import data into Python and rename it to dataSet .


# 读取电脑中的文件到Python中
dataSet = pd.read_csv("C:/Users/osc/Desktop/orange_cat.csv")

Core parameter

There are more than 30 parameters in pd.read_csv(). By configuring these parameters, you can filter and remove data at the same time during the process of reading .csv.

  • The official website description of pd.read_csv() parameters:
https://pandas.pydata.org/pandas-docs/version/0.16.2/generated/pandas.read_csv.html

The following are a few core parameters of the formula, generally I only use these.

 

 

If you want to know about the remaining more than 20 parameters, it is recommended to read on the official website of pandas.

Guess you like

Origin blog.csdn.net/pythonxuexi123/article/details/114979237