Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • Software and Tools
    • School Learning
    • Practice Coding Problems
  • GfG Premium
  • Python Tutorial
  • Interview Questions
  • Python Quiz
  • Python Glossary
  • Python Projects
  • Practice Python
  • Data Science With Python
  • Python Web Dev
  • DSA with Python
  • Python OOPs
Open In App
Next Article:
Python | Pandas dataframe.applymap()
Next article icon

Data analysis using Pandas

Last Updated : 11 Jul, 2025
Summarize
Comments
Improve
Suggest changes
Share
Like Article
Like
Report

Pandas are the most popular python library that is used for data analysis. It provides highly optimized performance with back-end source code purely written in C or Python. 

We can analyze data in Pandas with:

  • Pandas Series
  • Pandas DataFrames

Pandas Series

Series in Pandas is one dimensional(1-D) array defined in pandas that can be used to store any data type.

Creating Pandas Series

Python3
# Program to create series

# Import Panda Library
import pandas as pd

# Create series with Data, and Index
a = pd.Series(Data, index=Index)

Here, Data can be:

  1. A Scalar value which can be integerValue, string
  2. A Python Dictionary which can be Key, Value pair
  3. A Ndarray

Note: Index by default is from 0, 1, 2, ...(n-1) where n is the length of data.  

Create Series from List

 Creating series with predefined index values.

Python3
# Numeric data
Data = [1, 3, 4, 5, 6, 2, 9]

# Creating series with default index values
s = pd.Series(Data)

# predefined index values
Index = ['a', 'b', 'c', 'd', 'e', 'f', 'g']

si = pd.Series(Data, Index)

Output:

Create Series from List
 
 

Create Pandas Series from Dictionary

Program to Create Pandas series from Dictionary.

Python3
dictionary = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}

# Creating series of Dictionary type
sd = pd.Series(dictionary)

Output:

Create Pandas Series from Dictionary
Dictionary type data

Convert an Array to Pandas Series

Program to Create ndarray series.

Python3
# Defining 2darray
Data = [[2, 3, 4], [5, 6, 7]]

# Creating series of 2darray
snd = pd.Series(Data)

Output:

Convert an Array to Pandas Series
Data as Ndarray

Pandas DataFrames

The DataFrames in Pandas is a two-dimensional (2-D) data structure defined in pandas which consists of rows and columns.

Creating a Pandas DataFrame

Python3
# Program to Create DataFrame

# Import Library
import pandas as pd

# Create DataFrame with Data
a = pd.DataFrame(Data)

Here, Data can be:

  1. One or more dictionaries
  2. One or more Series
  3. 2D-numpy Ndarray

Create a Pandas DataFrame from multiple Dictionary

Program to Create a Dataframe with two dictionaries.

Python3
# Define Dictionary 1
dict1 = {'a': 1, 'b': 2, 'c': 3, 'd': 4}

# Define Dictionary 2
dict2 = {'a': 5, 'b': 6, 'c': 7, 'd': 8, 'e': 9}

# Define Data with dict1 and dict2
Data = {'first': dict1, 'second': dict2}

# Create DataFrame
df = pd.DataFrame(Data)

df

Output:

Create a Pandas DataFrame from multiple Dictionary
DataFrame with two dictionaries

Convert list of dictionaries to a Pandas DataFrame

Here, we are taking three dictionaries and with the help of from_dict() we convert them into Pandas DataFrame.

Python3
import pandas as pd
data_c = [
 {'A': 5, 'B': 0, 'C': 3, 'D': 3},
 {'A': 7, 'B': 9, 'C': 3, 'D': 5},
 {'A': 2, 'B': 4, 'C': 7, 'D': 6}]

pd.DataFrame.from_dict(data_c, orient='columns')

Output:

    A    B    C    D
0    5    0    3    3
1    7    9    3    5
2    2    4    7    6

Create DataFrame from Multiple Series

Program to create a dataframe of three Series.

Python3
import pandas as pd

# Define series 1
s1 = pd.Series([1, 3, 4, 5, 6, 2, 9])

# Define series 2    
s2 = pd.Series([1.1, 3.5, 4.7, 5.8, 2.9, 9.3])

# Define series 3
s3 = pd.Series(['a', 'b', 'c', 'd', 'e'])    

# Define Data
Data ={'first':s1, 'second':s2, 'third':s3}

# Create DataFrame
dfseries = pd.DataFrame(Data)            

dfseries

Output:

Create DataFrame from Multiple Series
DataFrame with three series

Convert a Array to Pandas Dataframe

One constraint has to be maintained while creating a DataFrame of 2D arrays - The dimensions of the 2D array must be the same.

Python3
# Program to create DataFrame from 2D array

# Import Library
import pandas as pd

# Define 2d array 1
d1 =[[2, 3, 4], [5, 6, 7]]

# Define 2d array 2
d2 =[[2, 4, 8], [1, 3, 9]]

# Define Data
Data ={'first': d1, 'second': d2}

# Create DataFrame
df2d = pd.DataFrame(Data)    

df2d

Output:

Convert a Array to Pandas Dataframe
DataFrame with 2d ndarray

Next Article
Python | Pandas dataframe.applymap()

A

Abhishek rajput
Improve
Article Tags :
  • Python
  • python-modules
Practice Tags :
  • python

Similar Reads

    Data Processing with Pandas
    Data Processing is an important part of any task that includes data-driven work. It helps us to provide meaningful insights from the data. As we know Python is a widely used programming language, and there are various libraries and tools available for data processing. In this article, we are going t
    10 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
    Python | Pandas dataframe.applymap()
    Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Dataframe.applymap() method applies a function that accepts and returns a scalar to ev
    2 min read
    Data Manipulation in Python using Pandas
    In Machine Learning, the model requires a dataset to operate, i.e. to train and test. But data doesn’t come fully prepared and ready to use. There are discrepancies like Nan/ Null / NA values in many rows and columns. Sometimes the data set also contains some of the rows and columns which are not ev
    6 min read
    Python | Pandas Dataframe.at[ ]
    Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric Python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas at[] is used to return data in a dataframe at the passed location. The passed l
    2 min read
    Creating a Pandas Series
    A Pandas Series is like a single column of data in a spreadsheet. It is a one-dimensional array that can hold many types of data such as numbers, words or even other Python objects. Each value in a Series is associated with an index, which makes data retrieval and manipulation easy. This article exp
    3 min read
`; $(commentSectionTemplate).insertBefore(".article--recommended"); } loadComments(); }); }); function loadComments() { if ($("iframe[id*='discuss-iframe']").length top_of_element && top_of_screen articleRecommendedTop && top_of_screen articleRecommendedBottom)) { if (!isfollowingApiCall) { isfollowingApiCall = true; setTimeout(function(){ if (loginData && loginData.isLoggedIn) { if (loginData.userName !== $('#followAuthor').val()) { is_following(); } else { $('.profileCard-profile-picture').css('background-color', '#E7E7E7'); } } else { $('.follow-btn').removeClass('hideIt'); } }, 3000); } } }); } $(".accordion-header").click(function() { var arrowIcon = $(this).find('.bottom-arrow-icon'); arrowIcon.toggleClass('rotate180'); }); }); window.isReportArticle = false; function report_article(){ if (!loginData || !loginData.isLoggedIn) { const loginModalButton = $('.login-modal-btn') if (loginModalButton.length) { loginModalButton.click(); } return; } if(!window.isReportArticle){ //to add loader $('.report-loader').addClass('spinner'); jQuery('#report_modal_content').load(gfgSiteUrl+'wp-content/themes/iconic-one/report-modal.php', { PRACTICE_API_URL: practiceAPIURL, PRACTICE_URL:practiceURL },function(responseTxt, statusTxt, xhr){ if(statusTxt == "error"){ alert("Error: " + xhr.status + ": " + xhr.statusText); } }); }else{ window.scrollTo({ top: 0, behavior: 'smooth' }); $("#report_modal_content").show(); } } function closeShareModal() { const shareOption = document.querySelector('[data-gfg-action="share-article"]'); shareOption.classList.remove("hover_share_menu"); let shareModal = document.querySelector(".hover__share-modal-container"); shareModal && shareModal.remove(); } function openShareModal() { closeShareModal(); // Remove existing modal if any let shareModal = document.querySelector(".three_dot_dropdown_share"); shareModal.appendChild(Object.assign(document.createElement("div"), { className: "hover__share-modal-container" })); document.querySelector(".hover__share-modal-container").append( Object.assign(document.createElement('div'), { className: "share__modal" }), ); document.querySelector(".share__modal").append(Object.assign(document.createElement('h1'), { className: "share__modal-heading" }, { textContent: "Share to" })); const socialOptions = ["LinkedIn", "WhatsApp","Twitter", "Copy Link"]; socialOptions.forEach((socialOption) => { const socialContainer = Object.assign(document.createElement('div'), { className: "social__container" }); const icon = Object.assign(document.createElement("div"), { className: `share__icon share__${socialOption.split(" ").join("")}-icon` }); const socialText = Object.assign(document.createElement("span"), { className: "share__option-text" }, { textContent: `${socialOption}` }); const shareLink = (socialOption === "Copy Link") ? Object.assign(document.createElement('div'), { role: "button", className: "link-container CopyLink" }) : Object.assign(document.createElement('a'), { className: "link-container" }); if (socialOption === "LinkedIn") { shareLink.setAttribute('href', `https://www.linkedin.com/sharing/share-offsite/?url=${window.location.href}`); shareLink.setAttribute('target', '_blank'); } if (socialOption === "WhatsApp") { shareLink.setAttribute('href', `https://api.whatsapp.com/send?text=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } if (socialOption === "Twitter") { shareLink.setAttribute('href', `https://twitter.com/intent/tweet?url=${window.location.href}`); shareLink.setAttribute('target', "_blank"); } shareLink.append(icon, socialText); socialContainer.append(shareLink); document.querySelector(".share__modal").appendChild(socialContainer); //adding copy url functionality if(socialOption === "Copy Link") { shareLink.addEventListener("click", function() { var tempInput = document.createElement("input"); tempInput.value = window.location.href; document.body.appendChild(tempInput); tempInput.select(); tempInput.setSelectionRange(0, 99999); // For mobile devices document.execCommand('copy'); document.body.removeChild(tempInput); this.querySelector(".share__option-text").textContent = "Copied" }) } }); // document.querySelector(".hover__share-modal-container").addEventListener("mouseover", () => document.querySelector('[data-gfg-action="share-article"]').classList.add("hover_share_menu")); } function toggleLikeElementVisibility(selector, show) { document.querySelector(`.${selector}`).style.display = show ? "block" : "none"; } function closeKebabMenu(){ document.getElementById("myDropdown").classList.toggle("show"); }
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