Home > Backend Development > Python Tutorial > How to read csv file in python

How to read csv file in python

爱喝马黛茶的安东尼
Release: 2019-06-20 14:43:31
Original
2403 people have browsed it

How to read csv file in python

How does python read CSV files? Here are three different ways for you:

Reading with normal method:

with open("fileName.csv") as file:     
    for line in  file:        
        print line
Copy after login

Reading with CSV standard library:

import csv
csv_reader = csv.reader(open("fileName.csv"))
for row in csv_reader:     
    print row
Copy after login

Read with pandas:

import pandas as pd
data = pd.read_csv("fileName.csv")
print data
data = pd.read_table("fileName.csv",sep=",")
print data
Copy after login

The above is the detailed content of How to read csv file in python. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template