CSV files are the “comma separated values”, these values are separated by commas, this file can be view like as excel file. In Python, Pandas is the most important library coming to data science. We need to deal with huge datasets while analyzing the data, which usually can get in CSV file format.
Let’s see the different ways to import csv file in Pandas.
Method #1: Using read_csv() method.
import pandas as pd
df.head( 10 )
|
Output:

Providing file_path.
import pandas as pd
filepath = r "C:\Gfg\datasets\nba.csv"
df = pd.read_csv(filepath)
print (df.head())
|
Output:

Method #2: Using csv
module.
One can directly import the csv files using csv
module.
import csv
import pandas as pd
with open (r "C:\Users\Admin\Downloads\nba.csv" ) as csv_file:
csv_reader = csv.reader(csv_file, delimiter = ',' )
df = pd.DataFrame([csv_reader], index = None )
df.head()
for val in list (df[ 1 ]):
print (val)
|
Output:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
19 Dec, 2018
Like Article
Save Article