SlideShare a Scribd company logo
INTRODUCTION TO PANDAS
A LIBRARY THAT IS USED FOR DATA MANIPULATION AND ANALYSIS TOOL
USING POWERFUL DATA STRUCTURES
TYPES OF DATA STRUCTUE IN PANDAS
Data Structure Dimensions Description
Series 1 1D labeled homogeneous
array, sizeimmutable.
Data Frames 2 General 2D labeled, size-
mutable tabular structure
with potentially
heterogeneously typed
columns.
Panel 3 General 3D labeled, size-
mutable array.
SERIES
• Series is a one-dimensional array like structure with homogeneous
data. For example, the following series is a collection of integers 10,
23, 56,
• … 10 23 56 17 52 61 73 90 26 72
DataFrame
• DataFrame is a two-dimensional array with heterogeneous data. For
example,
Name Age Gender Rating
Steve 32 Male 3.45
Lia 28 Female 4.6
Vin 45 Male 3.9
Katie 38 Female 2.78
Data Type of Columns
Column Type
Name String
Age Integer
Gender String
Rating Float
PANEL
• Panel is a three-dimensional data structure with heterogeneous data.
It is hard to represent the panel in graphical representation. But a
panel can be illustrated as a container of DataFrame.
DataFrame
• A Data frame is a two-dimensional data structure, i.e., data is aligned
in a tabular fashion in rows and columns.
• Features of DataFrame
• Potentially columns are of different types
• Size – Mutable
• Labeled axes (rows and columns)
• Can Perform Arithmetic operations on rows and columns
Structure
pandas.DataFrame
pandas.DataFrame(data, index , columns , dtype , copy )
• data
• data takes various forms like ndarray, series, map, lists, dict, constants and also
another DataFrame.
• index
• For the row labels, the Index to be used for the resulting frame is Optional Default
np.arrange(n) if no index is passed.
• columns
• For column labels, the optional default syntax is - np.arrange(n). This is only true if
no index is passed.
• dtype
• Data type of each column.
• copy
• This command (or whatever it is) is used for copying of data, if the default is False.
• Create DataFrame
• A pandas DataFrame can be created using various inputs like −
• Lists
• dict
• Series
• Numpy ndarrays
• Another DataFrame
Example
• Example
• import pandas as pd
• Data = [_______]
• Df = pd.DataFrame(data)
• Print df
Example 2
Import pandas as pd
Data = {‘Name’ : [‘__’. ‘__’],’Age’: [___]}
Df = pd.DataFrame(data)
print df
Example
• import pandas as pd
• data = [{'a': 1, 'b': 2},{'a': 5, 'b': 10, 'c': 20}]
• df = pd.DataFrame(data)
• print df
• ________________________________________
• import pandas as pd
• data = [{'a': 1, 'b': 2},{'a': 5, 'b': 10, 'c': 20}]
• df = pd.DataFrame(data, index=['first', 'second'])
• print df
• import pandas as pd
• data = [{'a': 1, 'b': 2},{'a': 5, 'b': 10, 'c': 20}]
• #With two column indices, values same as dictionary keys
• df1 = pd.DataFrame(data, index=['first', 'second'], columns=['a', 'b'])
• #With two column indices with one index with other name
• df2 = pd.DataFrame(data, index=['first', 'second'], columns=['a', 'b1'])
• print df1print df2
The following example shows how to create a DataFrame with
a list of dictionaries, row indices, and column indices.
• import pandas as pd
• data = [{'a': 1, 'b': 2},{'a': 5, 'b': 10, 'c': 20}]
• #With two column indices, values same as dictionary keys
• df1 = pd.DataFrame(data, index=['first', 'second'], columns=['a', 'b'])
• #With two column indices with one index with other name
• df2 = pd.DataFrame(data, index=['first', 'second'], columns=['a', 'b1'])
• print df1
• print df2
Create a DataFrame from Dict of Series
• import pandas as pd
• d = {'one' : pd.Series([1, 2, 3], index=['a', 'b', 'c']), 'two' : pd.Series([1,
2, 3, 4], index=['a', 'b', 'c', 'd'])}
• df = pd.DataFrame(d)
• print df
Column Addition
• import pandas as pd
• d = {'one' : pd.Series([1, 2, 3], index=['a', 'b', 'c']), 'two' : pd.Series([1, 2,
3, 4], index=['a', 'b', 'c', 'd'])}
• df = pd.DataFrame(d)
• # Adding a new column to an existing DataFrame object with column label
by passing new series
• print ("Adding a new column by passing as Series:")
• df['three']=pd.Series([10,20,30],index=['a','b','c'])
• print dfprint ("Adding a new column using the existing columns in
DataFrame:")
• df['four']=df['one']+df['three']
• print df
Column Deletion
• # Using the previous DataFrame, we will delete a
column
• # using del function
• import pandas as pd
• d = {'one' : pd.Series([1, 2, 3], index=['a', 'b', 'c']),
'two' : pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd']),
'three' : pd.Series([10,20,30], index=['a','b','c'])}
• df = pd.DataFrame(d)
• print ("Our dataframe is:")
• print df
• # using del function
• print ("Deleting the first column using DEL function:")
• del df['one']
• print df
# using pop function
• print ("Deleting another column using POP function:")
• df.pop('two')
• print df
Slicing in python
•import pandas as pd
d = {'one' : pd.Series([1, 2, 3], index=['a', 'b', 'c']),
'two' : pd.Series([1, 2, 3, 4], index=['a', 'b', 'c',
'd'])}
•df = pd.DataFrame(d)
•print df[2:4]
Addition of rows
• Df2 = pd.DataFrame([[5,6], [7,8]], columns = [‘a’, ‘b’])
• Df = df.append(df2 )
• Print df
Deletion of rows
• Df2 = pd.DataFrame([[5,6], [7,8]], columns = [‘a’, ‘b’])
• Df = df.drop(0)
• Print df
Reindexing
• import pandas as pd
• import numpy as np
df1 =
pd.DataFrame(np.random.randn(10,3),columns=['col1','col2','col3'])
• df2 =
pd.DataFrame(np.random.randn(7,3),columns=['col1','col2','col3'])df1
= df1.reindex_like(df2)print df1
Concatenating objects
• import pandas as pd
• One = pd.DataFrame({ ‘Name’: [‘__’] , ‘subject_id’: [‘__’], ‘marks’:
[‘__’]}, index = [] )
• two= pd.DataFrame({ ‘Name’: [‘__’] , ‘subject_id’: [‘__’], ‘marks’:
[‘__’]}, index = [] )
• Print pd.concat([one, two])
Handling categorical data
• There are many data that are repetitive for example gender , country , and codes are
always repetitive .
• Categorical variables can take on only a limited
• The categorical data type is useful in the following cases −
• A string variable consisting of only a few different values. Converting such a string
variable to a categorical variable will save some memory.
• The lexical order of a variable is not the same as the logical order (“one”, “two”,
“three”). By converting to a categorical and specifying an order on the categories,
sorting and min/max will use the logical order instead of the lexical order.
• As a signal to other python libraries that this column should be treated as a
categorical variable (e.g. to use suitable statistical methods or plot types).
• import pandas as pd
• cat = pd.Categorical(['a', 'b', 'c', 'a', 'b', 'c'])
• print cat
• ____________________________________________
• import pandas as pd
• import numpy as np
• cat = pd.Categorical(["a", "c", "c", np.nan], categories=["b", "a", "c"])
• df = pd.DataFrame({"cat":cat, "s":["a", "c", "c", np.nan]})
• print df.describe()
• print df["cat"].describe()
Introduction to pandas

More Related Content

What's hot

Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlib
Piyush rai
 
Data Analysis with Python Pandas
Data Analysis with Python PandasData Analysis with Python Pandas
Data Analysis with Python Pandas
Neeru Mittal
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
Damian T. Gordon
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
Sujith Kumar
 
List in Python
List in PythonList in Python
List in Python
Siddique Ibrahim
 
Introduction to Pandas and Time Series Analysis [PyCon DE]
Introduction to Pandas and Time Series Analysis [PyCon DE]Introduction to Pandas and Time Series Analysis [PyCon DE]
Introduction to Pandas and Time Series Analysis [PyCon DE]
Alexander Hendorf
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
nitamhaske
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
Girish Khanzode
 
Pandas
PandasPandas
Pandas
Jyoti shukla
 
Python Modules
Python ModulesPython Modules
Python Modules
Nitin Reddy Katkam
 
Chapter 03 python libraries
Chapter 03 python librariesChapter 03 python libraries
Chapter 03 python libraries
Praveen M Jigajinni
 
Data visualization in Python
Data visualization in PythonData visualization in Python
Data visualization in Python
Marc Garcia
 
Python dictionary
Python   dictionaryPython   dictionary
Python dictionary
Mohammed Sikander
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | Edureka
Edureka!
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
Megha V
 
Python list
Python listPython list
Python list
Mohammed Sikander
 
Python Seaborn Data Visualization
Python Seaborn Data Visualization Python Seaborn Data Visualization
Python Seaborn Data Visualization
Sourabh Sahu
 

What's hot (20)

Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlib
 
Data Analysis with Python Pandas
Data Analysis with Python PandasData Analysis with Python Pandas
Data Analysis with Python Pandas
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
 
Basics of Object Oriented Programming in Python
Basics of Object Oriented Programming in PythonBasics of Object Oriented Programming in Python
Basics of Object Oriented Programming in Python
 
List in Python
List in PythonList in Python
List in Python
 
Introduction to Pandas and Time Series Analysis [PyCon DE]
Introduction to Pandas and Time Series Analysis [PyCon DE]Introduction to Pandas and Time Series Analysis [PyCon DE]
Introduction to Pandas and Time Series Analysis [PyCon DE]
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
 
Pandas
PandasPandas
Pandas
 
Python Modules
Python ModulesPython Modules
Python Modules
 
Chapter 03 python libraries
Chapter 03 python librariesChapter 03 python libraries
Chapter 03 python libraries
 
Data visualization in Python
Data visualization in PythonData visualization in Python
Data visualization in Python
 
Python dictionary
Python   dictionaryPython   dictionary
Python dictionary
 
Pandas
PandasPandas
Pandas
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
 
Oop concepts in python
Oop concepts in pythonOop concepts in python
Oop concepts in python
 
Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | Edureka
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Python list
Python listPython list
Python list
 
Python Seaborn Data Visualization
Python Seaborn Data Visualization Python Seaborn Data Visualization
Python Seaborn Data Visualization
 

Similar to Introduction to pandas

Pandas Dataframe reading data Kirti final.pptx
Pandas Dataframe reading data  Kirti final.pptxPandas Dataframe reading data  Kirti final.pptx
Pandas Dataframe reading data Kirti final.pptx
Kirti Verma
 
pandas for series and dataframe.pptx
pandas for series and dataframe.pptxpandas for series and dataframe.pptx
pandas for series and dataframe.pptx
ssuser52a19e
 
DataFrame Creation.pptx
DataFrame Creation.pptxDataFrame Creation.pptx
DataFrame Creation.pptx
SarveshMariappan
 
pandas dataframe notes.pdf
pandas dataframe notes.pdfpandas dataframe notes.pdf
pandas dataframe notes.pdf
AjeshSurejan2
 
Unit 4_Working with Graphs _python (2).pptx
Unit 4_Working with Graphs _python (2).pptxUnit 4_Working with Graphs _python (2).pptx
Unit 4_Working with Graphs _python (2).pptx
prakashvs7
 
Presentation on Pandas in _ detail .pptx
Presentation on Pandas in _ detail .pptxPresentation on Pandas in _ detail .pptx
Presentation on Pandas in _ detail .pptx
16115yogendraSingh
 
pandas directories on the python language.pptx
pandas directories on the python language.pptxpandas directories on the python language.pptx
pandas directories on the python language.pptx
SumitMajukar
 
Python Pandas.pptx
Python Pandas.pptxPython Pandas.pptx
Python Pandas.pptx
SujayaBiju
 
Pandas-(Ziad).pptx
Pandas-(Ziad).pptxPandas-(Ziad).pptx
Pandas-(Ziad).pptx
Sivam Chinna
 
XII - 2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdf
XII -  2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdfXII -  2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdf
XII - 2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdf
KrishnaJyotish1
 
Unit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptxUnit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptx
prakashvs7
 
2 pandasbasic
2 pandasbasic2 pandasbasic
2 pandasbasic
pramod naik
 
Pandas pythonfordatascience
Pandas pythonfordatasciencePandas pythonfordatascience
Pandas pythonfordatascience
Nishant Upadhyay
 
Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet
Dr. Volkan OBAN
 
Lecture 9.pptx
Lecture 9.pptxLecture 9.pptx
Lecture 9.pptx
MathewJohnSinoCruz
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptx
ParveenShaik21
 
Working with Graphs _python.pptx
Working with Graphs _python.pptxWorking with Graphs _python.pptx
Working with Graphs _python.pptx
MrPrathapG
 
Getting started with Pandas Cheatsheet.pdf
Getting started with Pandas Cheatsheet.pdfGetting started with Pandas Cheatsheet.pdf
Getting started with Pandas Cheatsheet.pdf
SudhakarVenkey
 
Pandas.pptx
Pandas.pptxPandas.pptx

Similar to Introduction to pandas (20)

ppanda.pptx
ppanda.pptxppanda.pptx
ppanda.pptx
 
Pandas Dataframe reading data Kirti final.pptx
Pandas Dataframe reading data  Kirti final.pptxPandas Dataframe reading data  Kirti final.pptx
Pandas Dataframe reading data Kirti final.pptx
 
pandas for series and dataframe.pptx
pandas for series and dataframe.pptxpandas for series and dataframe.pptx
pandas for series and dataframe.pptx
 
DataFrame Creation.pptx
DataFrame Creation.pptxDataFrame Creation.pptx
DataFrame Creation.pptx
 
pandas dataframe notes.pdf
pandas dataframe notes.pdfpandas dataframe notes.pdf
pandas dataframe notes.pdf
 
Unit 4_Working with Graphs _python (2).pptx
Unit 4_Working with Graphs _python (2).pptxUnit 4_Working with Graphs _python (2).pptx
Unit 4_Working with Graphs _python (2).pptx
 
Presentation on Pandas in _ detail .pptx
Presentation on Pandas in _ detail .pptxPresentation on Pandas in _ detail .pptx
Presentation on Pandas in _ detail .pptx
 
pandas directories on the python language.pptx
pandas directories on the python language.pptxpandas directories on the python language.pptx
pandas directories on the python language.pptx
 
Python Pandas.pptx
Python Pandas.pptxPython Pandas.pptx
Python Pandas.pptx
 
Pandas-(Ziad).pptx
Pandas-(Ziad).pptxPandas-(Ziad).pptx
Pandas-(Ziad).pptx
 
XII - 2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdf
XII -  2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdfXII -  2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdf
XII - 2022-23 - IP - RAIPUR (CBSE FINAL EXAM).pdf
 
Unit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptxUnit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptx
 
2 pandasbasic
2 pandasbasic2 pandasbasic
2 pandasbasic
 
Pandas pythonfordatascience
Pandas pythonfordatasciencePandas pythonfordatascience
Pandas pythonfordatascience
 
Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet
 
Lecture 9.pptx
Lecture 9.pptxLecture 9.pptx
Lecture 9.pptx
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptx
 
Working with Graphs _python.pptx
Working with Graphs _python.pptxWorking with Graphs _python.pptx
Working with Graphs _python.pptx
 
Getting started with Pandas Cheatsheet.pdf
Getting started with Pandas Cheatsheet.pdfGetting started with Pandas Cheatsheet.pdf
Getting started with Pandas Cheatsheet.pdf
 
Pandas.pptx
Pandas.pptxPandas.pptx
Pandas.pptx
 

Recently uploaded

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
goswamiyash170123
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
Krisztián Száraz
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
Nguyen Thanh Tu Collection
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 

Recently uploaded (20)

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdfMASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
MASS MEDIA STUDIES-835-CLASS XI Resource Material.pdf
 
Advantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO PerspectiveAdvantages and Disadvantages of CMS from an SEO Perspective
Advantages and Disadvantages of CMS from an SEO Perspective
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
BÀI TẬP BỔ TRỢ TIẾNG ANH GLOBAL SUCCESS LỚP 3 - CẢ NĂM (CÓ FILE NGHE VÀ ĐÁP Á...
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 

Introduction to pandas

  • 1. INTRODUCTION TO PANDAS A LIBRARY THAT IS USED FOR DATA MANIPULATION AND ANALYSIS TOOL USING POWERFUL DATA STRUCTURES
  • 2. TYPES OF DATA STRUCTUE IN PANDAS Data Structure Dimensions Description Series 1 1D labeled homogeneous array, sizeimmutable. Data Frames 2 General 2D labeled, size- mutable tabular structure with potentially heterogeneously typed columns. Panel 3 General 3D labeled, size- mutable array.
  • 3. SERIES • Series is a one-dimensional array like structure with homogeneous data. For example, the following series is a collection of integers 10, 23, 56, • … 10 23 56 17 52 61 73 90 26 72
  • 4. DataFrame • DataFrame is a two-dimensional array with heterogeneous data. For example, Name Age Gender Rating Steve 32 Male 3.45 Lia 28 Female 4.6 Vin 45 Male 3.9 Katie 38 Female 2.78
  • 5. Data Type of Columns Column Type Name String Age Integer Gender String Rating Float
  • 6. PANEL • Panel is a three-dimensional data structure with heterogeneous data. It is hard to represent the panel in graphical representation. But a panel can be illustrated as a container of DataFrame.
  • 7. DataFrame • A Data frame is a two-dimensional data structure, i.e., data is aligned in a tabular fashion in rows and columns. • Features of DataFrame • Potentially columns are of different types • Size – Mutable • Labeled axes (rows and columns) • Can Perform Arithmetic operations on rows and columns
  • 10. • data • data takes various forms like ndarray, series, map, lists, dict, constants and also another DataFrame. • index • For the row labels, the Index to be used for the resulting frame is Optional Default np.arrange(n) if no index is passed. • columns • For column labels, the optional default syntax is - np.arrange(n). This is only true if no index is passed. • dtype • Data type of each column. • copy • This command (or whatever it is) is used for copying of data, if the default is False.
  • 11. • Create DataFrame • A pandas DataFrame can be created using various inputs like − • Lists • dict • Series • Numpy ndarrays • Another DataFrame
  • 12. Example • Example • import pandas as pd • Data = [_______] • Df = pd.DataFrame(data) • Print df Example 2 Import pandas as pd Data = {‘Name’ : [‘__’. ‘__’],’Age’: [___]} Df = pd.DataFrame(data) print df
  • 13. Example • import pandas as pd • data = [{'a': 1, 'b': 2},{'a': 5, 'b': 10, 'c': 20}] • df = pd.DataFrame(data) • print df • ________________________________________ • import pandas as pd • data = [{'a': 1, 'b': 2},{'a': 5, 'b': 10, 'c': 20}] • df = pd.DataFrame(data, index=['first', 'second']) • print df
  • 14. • import pandas as pd • data = [{'a': 1, 'b': 2},{'a': 5, 'b': 10, 'c': 20}] • #With two column indices, values same as dictionary keys • df1 = pd.DataFrame(data, index=['first', 'second'], columns=['a', 'b']) • #With two column indices with one index with other name • df2 = pd.DataFrame(data, index=['first', 'second'], columns=['a', 'b1']) • print df1print df2
  • 15. The following example shows how to create a DataFrame with a list of dictionaries, row indices, and column indices. • import pandas as pd • data = [{'a': 1, 'b': 2},{'a': 5, 'b': 10, 'c': 20}] • #With two column indices, values same as dictionary keys • df1 = pd.DataFrame(data, index=['first', 'second'], columns=['a', 'b']) • #With two column indices with one index with other name • df2 = pd.DataFrame(data, index=['first', 'second'], columns=['a', 'b1']) • print df1 • print df2
  • 16. Create a DataFrame from Dict of Series • import pandas as pd • d = {'one' : pd.Series([1, 2, 3], index=['a', 'b', 'c']), 'two' : pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])} • df = pd.DataFrame(d) • print df
  • 17. Column Addition • import pandas as pd • d = {'one' : pd.Series([1, 2, 3], index=['a', 'b', 'c']), 'two' : pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])} • df = pd.DataFrame(d) • # Adding a new column to an existing DataFrame object with column label by passing new series • print ("Adding a new column by passing as Series:") • df['three']=pd.Series([10,20,30],index=['a','b','c']) • print dfprint ("Adding a new column using the existing columns in DataFrame:") • df['four']=df['one']+df['three'] • print df
  • 18. Column Deletion • # Using the previous DataFrame, we will delete a column • # using del function • import pandas as pd • d = {'one' : pd.Series([1, 2, 3], index=['a', 'b', 'c']), 'two' : pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd']), 'three' : pd.Series([10,20,30], index=['a','b','c'])} • df = pd.DataFrame(d)
  • 19. • print ("Our dataframe is:") • print df • # using del function • print ("Deleting the first column using DEL function:") • del df['one'] • print df # using pop function • print ("Deleting another column using POP function:") • df.pop('two') • print df
  • 20. Slicing in python •import pandas as pd d = {'one' : pd.Series([1, 2, 3], index=['a', 'b', 'c']), 'two' : pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', 'd'])} •df = pd.DataFrame(d) •print df[2:4]
  • 21. Addition of rows • Df2 = pd.DataFrame([[5,6], [7,8]], columns = [‘a’, ‘b’]) • Df = df.append(df2 ) • Print df Deletion of rows • Df2 = pd.DataFrame([[5,6], [7,8]], columns = [‘a’, ‘b’]) • Df = df.drop(0) • Print df
  • 22. Reindexing • import pandas as pd • import numpy as np df1 = pd.DataFrame(np.random.randn(10,3),columns=['col1','col2','col3']) • df2 = pd.DataFrame(np.random.randn(7,3),columns=['col1','col2','col3'])df1 = df1.reindex_like(df2)print df1
  • 23. Concatenating objects • import pandas as pd • One = pd.DataFrame({ ‘Name’: [‘__’] , ‘subject_id’: [‘__’], ‘marks’: [‘__’]}, index = [] ) • two= pd.DataFrame({ ‘Name’: [‘__’] , ‘subject_id’: [‘__’], ‘marks’: [‘__’]}, index = [] ) • Print pd.concat([one, two])
  • 24. Handling categorical data • There are many data that are repetitive for example gender , country , and codes are always repetitive . • Categorical variables can take on only a limited • The categorical data type is useful in the following cases − • A string variable consisting of only a few different values. Converting such a string variable to a categorical variable will save some memory. • The lexical order of a variable is not the same as the logical order (“one”, “two”, “three”). By converting to a categorical and specifying an order on the categories, sorting and min/max will use the logical order instead of the lexical order. • As a signal to other python libraries that this column should be treated as a categorical variable (e.g. to use suitable statistical methods or plot types).
  • 25. • import pandas as pd • cat = pd.Categorical(['a', 'b', 'c', 'a', 'b', 'c']) • print cat • ____________________________________________ • import pandas as pd • import numpy as np • cat = pd.Categorical(["a", "c", "c", np.nan], categories=["b", "a", "c"]) • df = pd.DataFrame({"cat":cat, "s":["a", "c", "c", np.nan]}) • print df.describe() • print df["cat"].describe()