SlideShare ist ein Scribd-Unternehmen logo
1 von 26
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

Weitere ähnliche Inhalte

Was ist angesagt?

Python Seaborn Data Visualization
Python Seaborn Data Visualization Python Seaborn Data Visualization
Python Seaborn Data Visualization Sourabh Sahu
 
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,dictionarynitamhaske
 
pandas: Powerful data analysis tools for Python
pandas: Powerful data analysis tools for Pythonpandas: Powerful data analysis tools for Python
pandas: Powerful data analysis tools for PythonWes McKinney
 
Data Analysis with Python Pandas
Data Analysis with Python PandasData Analysis with Python Pandas
Data Analysis with Python PandasNeeru Mittal
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlibPiyush rai
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide shareDevashish Kumar
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in pythonTMARAGATHAM
 
File handling in Python
File handling in PythonFile handling in Python
File handling in PythonMegha V
 
Data visualization using R
Data visualization using RData visualization using R
Data visualization using RUmmiya Mohammedi
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented ProgrammingIqra khalil
 
Introduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsPhoenix
 
Introduction to numpy Session 1
Introduction to numpy Session 1Introduction to numpy Session 1
Introduction to numpy Session 1Jatin Miglani
 
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...Edureka!
 

Was ist angesagt? (20)

Python Seaborn Data Visualization
Python Seaborn Data Visualization Python Seaborn Data Visualization
Python Seaborn Data Visualization
 
NUMPY
NUMPY NUMPY
NUMPY
 
Python for Data Science
Python for Data SciencePython for Data Science
Python for Data Science
 
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
 
pandas: Powerful data analysis tools for Python
pandas: Powerful data analysis tools for Pythonpandas: Powerful data analysis tools for Python
pandas: Powerful data analysis tools for Python
 
Data Analysis with Python Pandas
Data Analysis with Python PandasData Analysis with Python Pandas
Data Analysis with Python Pandas
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlib
 
Data Analysis in Python
Data Analysis in PythonData Analysis in Python
Data Analysis in Python
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
 
File handling in Python
File handling in PythonFile handling in Python
File handling in Python
 
Python dictionary
Python   dictionaryPython   dictionary
Python dictionary
 
Data visualization using R
Data visualization using RData visualization using R
Data visualization using R
 
Introduction to numpy
Introduction to numpyIntroduction to numpy
Introduction to numpy
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Introduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data Analytics
 
Introduction to numpy Session 1
Introduction to numpy Session 1Introduction to numpy Session 1
Introduction to numpy Session 1
 
Python list
Python listPython list
Python list
 
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
 

Ähnlich wie 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.pptxKirti Verma
 
pandas for series and dataframe.pptx
pandas for series and dataframe.pptxpandas for series and dataframe.pptx
pandas for series and dataframe.pptxssuser52a19e
 
pandas dataframe notes.pdf
pandas dataframe notes.pdfpandas dataframe notes.pdf
pandas dataframe notes.pdfAjeshSurejan2
 
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).pptxprakashvs7
 
Presentation on Pandas in _ detail .pptx
Presentation on Pandas in _ detail .pptxPresentation on Pandas in _ detail .pptx
Presentation on Pandas in _ detail .pptx16115yogendraSingh
 
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.pptxSumitMajukar
 
Python Pandas.pptx
Python Pandas.pptxPython Pandas.pptx
Python Pandas.pptxSujayaBiju
 
Pandas-(Ziad).pptx
Pandas-(Ziad).pptxPandas-(Ziad).pptx
Pandas-(Ziad).pptxSivam 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).pdfKrishnaJyotish1
 
Unit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptxUnit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptxprakashvs7
 
Pandas pythonfordatascience
Pandas pythonfordatasciencePandas pythonfordatascience
Pandas pythonfordatascienceNishant 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
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxParveenShaik21
 
Working with Graphs _python.pptx
Working with Graphs _python.pptxWorking with Graphs _python.pptx
Working with Graphs _python.pptxMrPrathapG
 
Getting started with Pandas Cheatsheet.pdf
Getting started with Pandas Cheatsheet.pdfGetting started with Pandas Cheatsheet.pdf
Getting started with Pandas Cheatsheet.pdfSudhakarVenkey
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...anjaliyadav012327
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 

Kürzlich hochgeladen (20)

Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
JAPAN: ORGANISATION OF PMDA, PHARMACEUTICAL LAWS & REGULATIONS, TYPES OF REGI...
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 

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()