Home  >  Article  >  Backend Development  >  How to read csv file in python

How to read csv file in python

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-06-20 14:43:312250browse

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

Reading with CSV standard library:

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

Read with pandas:

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

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!

Statement:
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