I tried several times to import CSV file into python 2.7.15 but it fail. Please suggest how to import CSV in Python.
Thank you
I tried several times to import CSV file into python 2.7.15 but it fail. Please suggest how to import CSV in Python.
Thank you
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.