SlideShare a Scribd company logo
DATAFRAME
OPERATIONS
BY:
HARSH, KARTIK, ANSH, ROHIT
AGGREGATION
• Aggregation functions allow you to summarize the data in a DataFrame by calculating a single
value for each column.
• The most common aggregation functions are:
sum(), mean(), median(), mode(), std(), and var().
To use an aggregation function, you can pass it to the agg() method of a DataFrame.
For example, to calculate the mean of each column in a DataFrame, you would use the following
code:
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
df.agg(['mean'])
GROUP BY
• The groupby() method allows you to group the rows in a DataFrame by one or
more columns.
• This can be useful for performing aggregation operations on specific groups of
data.
• For example, to calculate the mean of each column in a DataFrame, grouped by
the "A" column, you would use the following code:
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
df.groupby('A').agg(['mean'])
SORTING
• The sort_values() method allows you to sort the rows in a DataFrame by one or more
columns.
• You can specify whether to sort in ascending or descending order by passing the
ascending parameter to the sort_values() method.
• For example, to sort the rows in a DataFrame by the "A" column in ascending order,
you would use the following code
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
df.sort_values('A', ascending=True)
RENAMING INDEX
• The set_index() method allows you to rename the index of a DataFrame.
• You can pass a column name or a list of column names to the set_index() method.
• For example, to rename the index of a DataFrame to the "A" column, you would
use the following code:
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
df.set_index('A')
PIVOTING
• The pivot_table() method allows you to reshape a DataFrame by pivoting the rows
and columns.
• This can be useful for creating summary tables and cross-tabulations.
• For example, to create a summary table of the mean of each column in a
DataFrame, grouped by the "A" column, you would use the following code
import pandas as pd
df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})
df.pivot_table(values='B', index='A', aggfunc='mean')

More Related Content

PPTX
Pandas Dataframe reading data Kirti final.pptx
PPTX
introduction to data structures in pandas
PPTX
Pandas yayyyyyyyyyyyyyyyyyin Python.pptx
PPTX
DataFrame Creation.pptx
PPTX
DataStructures in Pyhton Pandas and numpy.pptx
PPTX
Data Frame Data structure in Python pandas.pptx
PPTX
Unit 1 Ch 2 Data Frames digital vis.pptx
PPTX
Data Analysis with Python Pandas
Pandas Dataframe reading data Kirti final.pptx
introduction to data structures in pandas
Pandas yayyyyyyyyyyyyyyyyyin Python.pptx
DataFrame Creation.pptx
DataStructures in Pyhton Pandas and numpy.pptx
Data Frame Data structure in Python pandas.pptx
Unit 1 Ch 2 Data Frames digital vis.pptx
Data Analysis with Python Pandas

Similar to Data Science ppt on dataframe operations.pptx (20)

PPTX
Pandas csv
PPTX
Group B - Pandas Pandas is a powerful Python library that provides high-perfo...
PPTX
ppanda.pptx
PPTX
Python Library-Series.pptx
PPTX
Pandas-(Ziad).pptx
PPTX
Python Pandas.pptx
PPTX
introductiontopandas- for 190615082420.pptx
PPTX
interenship.pptx
PPTX
dataframe_operations and various functions
PPTX
Introduction to pandas
PPTX
Unit 4_Working with Graphs _python (2).pptx
PPTX
Python and CSV Connectivity
PPTX
Python-for-Data-Analysis.pptx
PPTX
Introduction To Pandas:Basics with syntax and examples.pptx
PPTX
Unit 3_Numpy_Vsp.pptx
PPTX
PANDAS IN PYTHON (Series and DataFrame)
PDF
Pandas in Depth_ Data Manipultion(Chapter 5)(Important).pdf
PPTX
Introduccion a Pandas_cargar datos, modelar, analizar, manipular y prepararlo...
PDF
Lecture on Python Pandas for Decision Making
PPTX
Unit 3_Numpy_VP.pptx
Pandas csv
Group B - Pandas Pandas is a powerful Python library that provides high-perfo...
ppanda.pptx
Python Library-Series.pptx
Pandas-(Ziad).pptx
Python Pandas.pptx
introductiontopandas- for 190615082420.pptx
interenship.pptx
dataframe_operations and various functions
Introduction to pandas
Unit 4_Working with Graphs _python (2).pptx
Python and CSV Connectivity
Python-for-Data-Analysis.pptx
Introduction To Pandas:Basics with syntax and examples.pptx
Unit 3_Numpy_Vsp.pptx
PANDAS IN PYTHON (Series and DataFrame)
Pandas in Depth_ Data Manipultion(Chapter 5)(Important).pdf
Introduccion a Pandas_cargar datos, modelar, analizar, manipular y prepararlo...
Lecture on Python Pandas for Decision Making
Unit 3_Numpy_VP.pptx
Ad

Recently uploaded (20)

PPTX
history of c programming in notes for students .pptx
PDF
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
PDF
Digital Strategies for Manufacturing Companies
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
System and Network Administraation Chapter 3
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PDF
Nekopoi APK 2025 free lastest update
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
top salesforce developer skills in 2025.pdf
PPTX
Introduction to Artificial Intelligence
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Transform Your Business with a Software ERP System
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
Reimagine Home Health with the Power of Agentic AI​
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
history of c programming in notes for students .pptx
EN-Survey-Report-SAP-LeanIX-EA-Insights-2025.pdf
Digital Strategies for Manufacturing Companies
Odoo Companies in India – Driving Business Transformation.pdf
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
System and Network Administraation Chapter 3
Design an Analysis of Algorithms II-SECS-1021-03
Nekopoi APK 2025 free lastest update
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
top salesforce developer skills in 2025.pdf
Introduction to Artificial Intelligence
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Navsoft: AI-Powered Business Solutions & Custom Software Development
Transform Your Business with a Software ERP System
PTS Company Brochure 2025 (1).pdf.......
Reimagine Home Health with the Power of Agentic AI​
Upgrade and Innovation Strategies for SAP ERP Customers
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Ad

Data Science ppt on dataframe operations.pptx

  • 2. AGGREGATION • Aggregation functions allow you to summarize the data in a DataFrame by calculating a single value for each column. • The most common aggregation functions are: sum(), mean(), median(), mode(), std(), and var(). To use an aggregation function, you can pass it to the agg() method of a DataFrame. For example, to calculate the mean of each column in a DataFrame, you would use the following code: import pandas as pd df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}) df.agg(['mean'])
  • 3. GROUP BY • The groupby() method allows you to group the rows in a DataFrame by one or more columns. • This can be useful for performing aggregation operations on specific groups of data. • For example, to calculate the mean of each column in a DataFrame, grouped by the "A" column, you would use the following code: import pandas as pd df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}) df.groupby('A').agg(['mean'])
  • 4. SORTING • The sort_values() method allows you to sort the rows in a DataFrame by one or more columns. • You can specify whether to sort in ascending or descending order by passing the ascending parameter to the sort_values() method. • For example, to sort the rows in a DataFrame by the "A" column in ascending order, you would use the following code import pandas as pd df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}) df.sort_values('A', ascending=True)
  • 5. RENAMING INDEX • The set_index() method allows you to rename the index of a DataFrame. • You can pass a column name or a list of column names to the set_index() method. • For example, to rename the index of a DataFrame to the "A" column, you would use the following code: import pandas as pd df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}) df.set_index('A')
  • 6. PIVOTING • The pivot_table() method allows you to reshape a DataFrame by pivoting the rows and columns. • This can be useful for creating summary tables and cross-tabulations. • For example, to create a summary table of the mean of each column in a DataFrame, grouped by the "A" column, you would use the following code import pandas as pd df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]}) df.pivot_table(values='B', index='A', aggfunc='mean')