-3

I tried several times to import CSV file into python 2.7.15 but it fail. Please suggest how to import CSV in Python.

csv into python

Thank you

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
Mohamed Abass
  • 71
  • 1
  • 1
  • 9

1 Answers1

10

There are two ways to import a csv file in Python.

First: Using standard Python csv

import csv
with open('filename.csv') as csv_file:
    csv_read=csv.reader(csv_file, delimiter=',')

Second: Using pandas

import pandas as pd
data = pd.read_csv('filename.csv')
data.head() # to display the first 5 lines of loaded data

I would suggest to import using pandas since that's the more convenient way to do so.

cedricbellet
  • 148
  • 2
  • 12
uday more
  • 116
  • 1
  • 4