SlideShare a Scribd company logo
DATAFRAME IN PYTHON
Dr. B. Subashini
Assistant Professor of Computer Applications,
V.V.Vanniaperumal College for Women,
Virudhunagar.
DATAFRAME
A Data frame is a two-dimensional data structure in which data
are organized in a tabular fashion using rows and columns .
Basic features of data frame are:
• Columns of different data types.
• Size is mutable.
• Data frame has labelled axes for rows and columns.
• Arithmetic operations can be performed on rows and
columns.
CREATING A DATA FRAME
A Data frame can be created using the pandas.DataFrame function
from pandas library.
SYNTAX
pandas.DataFrame(data,index,colums)
SAMPLE PROGRAM
Create a data frame with 10 rows and 4 columns which has
random values . And perform the following task
a) Specify the index values with difference of 10.
b) Apply sum to data frame.
c) Find the mean of the first column.
d) Find the minimum values in last two rows of data frame.
PROGRAM
Create a data frame with 10 rows and 4 columns
which has random values
import numpy as np
import pandas as pd
df=pd.DataFrame(np.random.randn
(10,4))
print(df)
OUTPUT
Specify the index values with difference of 10.
print(“RENAMEIND INDEX IN
THE DATAFRAME”)
print(“***************************”)
df2=df.rename(index = lambda x:
(x*10)+10)
print(df2)
OUTPUT
Apply sum to data frame
print("APPLYING THE SUM TO
DATAFRAME")
print("*************************")
print("COLUMN WISE SUM")
print("---------------")
print(df.sum(axis=0))
print("ROW WISE SUM")
print("------------")
print(df.sum(axis=1))
OUTPUT
Find the mean of the first column
print("FINDING THE MEAN OF
THE FIRST COLUMN")
print("****************************")
print(df[0].mean())
OUTPUT
Find the minimum values in last two rows of data frame
print("LAST TWO ROWS IN
DATAFRAME")
print("--------------------------")
print(df.tail(2))
print("THE MINIMUM VALUES")
print("------------------")
print(df.tail(2).min())
OUTPU
T

More Related Content

PPTX
Group B - Pandas Pandas is a powerful Python library that provides high-perfo...
PPTX
Basic data manipulation with pandas pandas
PPTX
2. Data Preprocessing with Numpy and Pandas.pptx
PPTX
PPTX
Pandas Dataframe reading data Kirti final.pptx
PPTX
python-pandas-For-Data-Analysis-Manipulate.pptx
PPTX
Python Pandas.pptx
PPTX
Lecture 1 Pandas Basics.pptx machine learning
Group B - Pandas Pandas is a powerful Python library that provides high-perfo...
Basic data manipulation with pandas pandas
2. Data Preprocessing with Numpy and Pandas.pptx
Pandas Dataframe reading data Kirti final.pptx
python-pandas-For-Data-Analysis-Manipulate.pptx
Python Pandas.pptx
Lecture 1 Pandas Basics.pptx machine learning

Similar to HANDLING DATAFRAME IN PYTHON WITH AN EXAMPLE (20)

PPTX
Python-for-Data-Analysis.pptx
PPTX
interenship.pptx
PDF
Python pandas I .pdf gugugigg88iggigigih
PPTX
Pandas-(Ziad).pptx
PPTX
Meetup Junio Data Analysis with python 2018
PDF
XII - 2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdf
PPTX
Unit 3_Numpy_VP.pptx
PPTX
PPT on Data Science Using Python
PPTX
Pandas yayyyyyyyyyyyyyyyyyin Python.pptx
PPTX
Pandas
PPTX
Unit 3_Numpy_VP.pptx
PPTX
More on Pandas.pptx
PPTX
DataFrame Creation.pptx
PPTX
Data Visualization_pandas in hadoop.pptx
PPTX
To understand the importance of Python libraries in data analysis.
PDF
Introduction to Machine Learning with SciKit-Learn
PPTX
Lecture 9.pptx
PPTX
Pandas csv
PPTX
Lecture 3 intro2data
PPTX
Pandas.pptx
Python-for-Data-Analysis.pptx
interenship.pptx
Python pandas I .pdf gugugigg88iggigigih
Pandas-(Ziad).pptx
Meetup Junio Data Analysis with python 2018
XII - 2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdf
Unit 3_Numpy_VP.pptx
PPT on Data Science Using Python
Pandas yayyyyyyyyyyyyyyyyyin Python.pptx
Pandas
Unit 3_Numpy_VP.pptx
More on Pandas.pptx
DataFrame Creation.pptx
Data Visualization_pandas in hadoop.pptx
To understand the importance of Python libraries in data analysis.
Introduction to Machine Learning with SciKit-Learn
Lecture 9.pptx
Pandas csv
Lecture 3 intro2data
Pandas.pptx
Ad

Recently uploaded (20)

PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Encapsulation theory and applications.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Machine learning based COVID-19 study performance prediction
PDF
Spectral efficient network and resource selection model in 5G networks
PPTX
Understanding_Digital_Forensics_Presentation.pptx
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Empathic Computing: Creating Shared Understanding
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Encapsulation theory and applications.pdf
Network Security Unit 5.pdf for BCA BBA.
Programs and apps: productivity, graphics, security and other tools
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Machine learning based COVID-19 study performance prediction
Spectral efficient network and resource selection model in 5G networks
Understanding_Digital_Forensics_Presentation.pptx
The AUB Centre for AI in Media Proposal.docx
Review of recent advances in non-invasive hemoglobin estimation
Empathic Computing: Creating Shared Understanding
MYSQL Presentation for SQL database connectivity
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Chapter 3 Spatial Domain Image Processing.pdf
Mobile App Security Testing_ A Comprehensive Guide.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Ad

HANDLING DATAFRAME IN PYTHON WITH AN EXAMPLE

  • 1. DATAFRAME IN PYTHON Dr. B. Subashini Assistant Professor of Computer Applications, V.V.Vanniaperumal College for Women, Virudhunagar.
  • 2. DATAFRAME A Data frame is a two-dimensional data structure in which data are organized in a tabular fashion using rows and columns . Basic features of data frame are: • Columns of different data types. • Size is mutable. • Data frame has labelled axes for rows and columns. • Arithmetic operations can be performed on rows and columns.
  • 3. CREATING A DATA FRAME A Data frame can be created using the pandas.DataFrame function from pandas library. SYNTAX pandas.DataFrame(data,index,colums) SAMPLE PROGRAM
  • 4. Create a data frame with 10 rows and 4 columns which has random values . And perform the following task a) Specify the index values with difference of 10. b) Apply sum to data frame. c) Find the mean of the first column. d) Find the minimum values in last two rows of data frame. PROGRAM
  • 5. Create a data frame with 10 rows and 4 columns which has random values import numpy as np import pandas as pd df=pd.DataFrame(np.random.randn (10,4)) print(df) OUTPUT
  • 6. Specify the index values with difference of 10. print(“RENAMEIND INDEX IN THE DATAFRAME”) print(“***************************”) df2=df.rename(index = lambda x: (x*10)+10) print(df2) OUTPUT
  • 7. Apply sum to data frame print("APPLYING THE SUM TO DATAFRAME") print("*************************") print("COLUMN WISE SUM") print("---------------") print(df.sum(axis=0)) print("ROW WISE SUM") print("------------") print(df.sum(axis=1)) OUTPUT
  • 8. Find the mean of the first column print("FINDING THE MEAN OF THE FIRST COLUMN") print("****************************") print(df[0].mean()) OUTPUT
  • 9. Find the minimum values in last two rows of data frame print("LAST TWO ROWS IN DATAFRAME") print("--------------------------") print(df.tail(2)) print("THE MINIMUM VALUES") print("------------------") print(df.tail(2).min()) OUTPU T