Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Data preprocessing
  • Data Manipulation
  • Data Analysis using Pandas
  • EDA
  • Pandas Exercise
  • Pandas AI
  • Numpy
  • Matplotlib
  • Plotly
  • Data Analysis
  • Machine Learning
  • Data science
Open In App
Next Article:
Creating a dataframe using Excel files
Next article icon

Creating a dataframe using CSV files

Last Updated : 08 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

CSV (Comma-Separated Values) files are widely used in data science for storing tabular data, similar to Excel sheets. In Python the Pandas library is essential for handling and analyzing large datasets stored in CSV format. Below are three methods to create a Pandas DataFrame from a CSV file:

Method 1: Using read_csv()

read_csv() function is the most commonly used and efficient way to read CSV files into a DataFrame. We can download the dataset from here.

Python
import pandas as pd  # Load CSV file into a DataFrame df = pd.read_csv("CardioGoodFitness.csv") print(df.head()) 

Output:

csv-to-df-pandas

Displays the first few rows of the dataset with columns and their respective values.

Method 2: Using read_table()

read_table() function allows us to specify a custom delimiter, such as a comma to read CSV files.

Python
import pandas as pd  # Load CSV file using read_table with a comma delimiter df = pd.read_table("CardioGoodFitness.csv", delimiter=",") print(df.head()) 

Output:

csv-to-df-pandas

Method 3: Using the csv Module (Manual Way)

We can also use Python’s built-in csv module to read the file and then manually convert it to a Pandas DataFrame.

Python
import pandas as pd import csv  with open("CardioGoodFitness.csv") as csv_file:     csv_reader = csv.reader(csv_file)     # Create DataFrame from the CSV reader object     df = pd.DataFrame(list(csv_reader)) df.head() 

Output: 

Screenshot-2025-04-08-160634

Using the csv Module

Key Takeaways:

  • Use read_csv() for simplicity and efficiency when working with standard CSV files.
  • Use read_table() if your data uses a custom delimiter or requires specific parsing options.
  • Use the csv module for advanced parsing needs or when integrating with other Python libraries.


Next Article
Creating a dataframe using Excel files

A

AmiyaRanjanRout
Improve
Article Tags :
  • Python
  • Python pandas-dataFrame
  • Python-pandas
Practice Tags :
  • python

Similar Reads

  • Creating a dataframe using Excel files
    Let's see how to read excel files to Pandas dataframe objects using Pandas. To get the SampleWork.xlsx file click here. Code #1 : Read the above excel file using read_excel() method of pandas. [GFGTABS] Python # import pandas lib as pd import pandas as pd # read by default 1st sheet of an excel file
    4 min read
  • Creating a Pandas dataframe using list of tuples
    A Pandas DataFrame is an important data structure used for organizing and analyzing data in Python. Converting a list of tuples into a DataFrame makes it easier to work with data. In this article we'll see ways to create a DataFrame from a list of tuples. 1. Using pd.DataFrame()The simplest method t
    2 min read
  • Saving a Pandas Dataframe as a CSV
    In this article, we will learn how we can export a Pandas DataFrame to a CSV file by using the Pandas to_csv() method. By default, the to csv() method exports DataFrame to a CSV file with row index as the first column and comma as the delimiter. Table of Content Export CSV to a Working DirectorySavi
    2 min read
  • Creating Pandas dataframe using list of lists
    In this article, we will explore the Creating Pandas data frame using a list of lists. A Pandas DataFrame is a versatile 2-dimensional labeled data structure with columns that can contain different data types. It is widely utilized as one of the most common objects in the Pandas library. There are v
    4 min read
  • Create a Pandas DataFrame from Lists
    Converting lists to DataFrames is crucial in data analysis, Pandas enabling you to perform sophisticated data manipulations and analyses with ease. List to Dataframe Example # Simple listdata = [1, 2, 3, 4, 5]# Convert to DataFramedf = pd.DataFrame(data, columns=['Numbers'])Here we will discuss diff
    5 min read
  • Creating views on Pandas DataFrame
    Many times while doing data analysis we are dealing with a large data set, having a lot of attributes. All the attributes are not necessarily equally important. As a result, we want to work with only a set of columns in the dataframe. For that purpose, let's see how we can create views on the Datafr
    2 min read
  • Creating views on Pandas DataFrame | Set - 2
    Prerequisite: Creating views on Pandas DataFrame | Set - 1 Many times while doing data analysis we are dealing with a large data set has a lot of attributes. All the attributes are not necessarily equally important. As a result, we want to work with only a set of columns in the dataframe. For that p
    2 min read
  • Copying Csv Data Into Csv Files Using Python
    CSV files, the stalwarts of information exchange, can be effortlessly harnessed to extract specific data or merge insights from multiple files. In this article, we unveil five robust approaches, transforming you into a virtuoso of CSV data migration in Python. Empower your data-wrangling endeavors,
    4 min read
  • Create pandas dataframe from lists using zip
    One of the way to create Pandas DataFrame is by using zip() function. You can use the lists to create lists of tuples and create a dictionary from it. Then, this dictionary can be used to construct a dataframe. zip() function creates the objects and that can be used to produce single item at a time.
    2 min read
  • Read a zipped file as a Pandas DataFrame
    In this article, we will try to find out how can we read data from a zip file using a panda data frame.  Why we need a zip file? People use related groups of files together and to make files compact, so they are easier and faster to share via the web. Zip files are ideal for archiving since they sav
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences