SlideShare ist ein Scribd-Unternehmen logo
Python Library – Pandas
It is a most famous Python package for data science, which offers
powerful and flexible data structures that make data analysis and
manipulation easy. Pandas make data importing and data analyzing
much easier. Pandas build on packages like NumPy and matplotlib
to give us a single & convenient place for data analysis and
visualization work. Pandas is a high level data manipulation tool
developed by Wes McKinney.
SYLLABUS 2022-23
Basic Features of Panda
1. With a pandas dataframe, we can have different data types (float, int, string,
datetime, etc) all in one place
2. Columns from a Panda data structure can be deleted or inserted
3. Good IO capabilities; Easily pull data from a MySQL database directly into a
data frame
4. Itsupportsgroupbyoperationfordataaggregationandtransformationandalowshigh
performancemergingandjoiningofdata.
5. It can easily select subsets of data from bulky datasets and even combine
multiple data sets together.
6. It has the functionality to find and fill missing data.
7. Reshaping and pivoting of data sets into different forms.
8. Label-based slicing, indexing and subsetting of large data sets.
9. It allows us to apply operations to independent groups within the data.
10. It supports advanced time-series functionality( which is the use of a model
to predict future values based on previously observed values.
11. It supports visualization by integrating libraries such as matplotlib, ans
seaborn etc. Pandas is best at handling hugs tabular datasets comprising
different data formats.
Data Structures in Pandas
A data structure is a way of storing and organizing data in a computer so that it can be
accessed and worked with in an appropriate way.
Important data structures of pandas are–Series,DataFrame, Panel
1. Series
Series is like a one-dimensional array like structure with homogeneous data. For example,
the following series is a collection of integers.
Basic feature of series are
 Homogeneous data
 Size Immutable
 Values of Data Mutable
Pandas Series
It is like one-dimensional array capable of holding data of any type (integer, string, float, python objects,
etc.). Series can be created using Series() method. Any list or dictionary data can be converted into series
using this method.
A series can be described as an ordered dictionary with mapping of index values to data values.
Create an Empty Series
s1--------
series variable
pd-------
alternate name given to Pandas module
import pandas as pd
s1 = pd.Series()
print(s1)
Output
Series([], dtype: float64)
Creating Series using Series() with arguments
Syntax :- pandas.Series( data, index, dtype, copy)
Data supplied to Series() can be
 A sequence( list)
 An ndarray
 A scalar value
 A python dictionary
 A mathematical expression or function
Creating Series using List
Like array, a list is also a one-dimensional datatype. But the difference lies in the fact that an array contains elements of
same datatype, while a list may contain elements of same or different data types.
Syntax :- pandas.Series( data, index = idx)
import pandas as pd
s1=pd.Series([10,20,30,40,50])
print(s1)
*Pandas create a default index and automatically assigns the index value from 0 to 4, which is length of the list-1
import pandas as pd
s1=pd.Series([10,20,30,40])
s1.index=['a', 'b', 'c', 'd']
print(s1)
(or)
import pandas as pd
s1=pd.Series([10,20,30,40], index= ['a', 'b', 'c', 'd'])
print(s1)
Creating Series using nd array
import pandas as pd
s1=pd.Series([1,2,3.3,4,7])
print(s1)
* One of the element in the list, is a float value, it will convert the rest of the integer values into float and displays a
float series.
range() method
import pandas as pd
s1=pd.Series(range(4))
print(s1)
Access single and multiple values based on index.
import pandas as pd
s1=pd.Series([2,3,5.3,7,9], index=['first','sec','third','fourth','fifth'])
print(s1['sec'])
Output
3.0
import pandas as pd
s1=pd.Series([2,3,5.3,7,9], index=['first','sec','third','fourth','fifth'])
print(s1)
print(s1[['sec','third','fifth']])
Values and index
import pandas as pd
s1=pd.Series([10,20,30,40,50],index=['First', 'sec', 'third', 'forth', 'fifth'])
print(s1.values)
import pandas as pd
s1=pd.Series([10,20,30,40,50],index=['First', 'sec', 'third', 'forth','fifth'])
print(s1.index)
Accessing data from a Series with Position
Indexing, slicing and accessing data from a series
import pandas as pd
s1=pd.Series([1,2,3,4,5], index=['a', 'b', 'c', 'd', 'e'])
print(s1[0])
print(s1[:3])
print(s1[-3:])
iloc and loc
iloc – used for indexing or selecting based on position ie, by row number and column number. It refers to position-
based indexing.
Syntax
iloc = [<row number range>,<column number range>]
It refers to name-based
loc - used for indexing or selecting based on name ie, by row name and column name.
indexing.
Syntax
iloc = [<list of row names >,<list of column names>]
import pandas as pd
s1=pd.Series([1,2,3,4,5], index=['a', 'b', 'c', 'd', 'e'])
print(s1.iloc[1:4])
print(s1.loc['b':'e'])
Retrieving values from Series using head()and tail () functions
Series.head() function in a series fetches first ‘n’ values from a pandas object. By default, it gives us the top 5 rows of data
in the series. Series.tail() function displays the last 5 elements by default.
import pandas as pd
s1=pd.Series([10,20,30,40,50,60,70,80,90])
print(s1.head())
import pandas as pd
s1=pd.Series([10,20,30,40,50,60,70,80,90])
print(s1.head(3))
import pandas as pd
s1=pd.Series([10,20,30,40,50,60,70,80,90])
print(s1.tail(2))
Creating a Series from Scalar or Constant Values
A data is a scalar value for which it is a must to provide an index. This constant value shall be repeated to match the
length of the index.
import pandas as pd
s1=pd.Series(55, index=['a', 'b', 'c', 'd', 'e'])
print(s1)
Note :- here 55 is repeated for 5 times (as per no of index)
import pandas as pd
s1=pd.Series(55, index=[1,2,3,4,5])
print(s1)
Using range() method
import pandas as pd
s1=pd.Series(40, index=range(0,4))
print(s1)
import pandas as pd
s1=pd.Series(40, index=range(1,6,2))
print(s1)
Creating a Series with index of String (text) type
String or text can be used as an index to the elements of a series.
import pandas as pd
s1=pd.Series('Stay Home', index=['Madhav', 'Smitha', 'Vivek'])
print(s1)
Creating a Series with range() and for loop
import pandas as pd
s1=pd.Series(range(1,15,3), index=[x for x in 'abcde'])
print(s1)
Creating a Series using two different lists
* Two lists are passed as arguments to Series()method
import pandas as pd
months=['jan', 'feb', 'mar', 'apr', 'may']
no_days=[31,28,31,30,31]
s1=pd.Series(no_days,index=months)
print(s1)
Creating a Series using missing values [NaN]
We may need to create a series object for which size is defined but some element or data are missing. This is handled
by defining NaN [Not a Number], which is an attribute of Numpy library, defining a missing value using np.NaN.
import pandas as pd
import numpy as np
s1=pd.Series([31,28,31,np.NaN,31])
print(s1)
Creating Series from Dictionary
Using dictionary for creating a series gives us the advantage of built-in keys used as index. We do not require declaring
an index as a separate list: instead, built-in keys will be treated as the index
import pandas as pd
data = {'a' : 0., 'b' : 1., 'c' : 2.}
s = pd.Series(data)
print(s)
* A dictionary can be passed as input and if no index is specified, the dictionary keys are taken in the
sorted order to construct index
import pandas as pd1
data = {'a' : 0., 'b' : 1., 'c' : 2.}
s = pd1.Series(data,index=['b','c','d','a'])
print(s)
import pandas as pd
s1=pd.Series({'Jan':31,'Feb':28,'Mar':31,'Apr':30})
print(s1)
Naming a series
We can give a name to the two columns, index and values of a series using ‘name’ property.
import pandas as pd
s=pd.Series({'Jan':31,'Feb':28,'Mar':31,'Apr':30})
#naming the series and index
s.name='Days'
s.index.name='Month'
print(s)
* The index column is assigned the name ‘Month’ and data is assigned the name ‘Days’
Creating a Series using a mathematical expression/function
import pandas as pd
import numpy as np
s1=np.arange(5,10)
print(s1)
s2=pd.Series(index=s1,data=s1*4)
print(s2)
import pandas as pd
import numpy as np
s1=np.arange(5,10)
print(s1)
s2=pd.Series(index=s1,data=s1**4)
print(s2)
Mathematical operation on series
import pandas as pd
s1=pd.Series([10,20,30,40,50], index=[1,2,3,4,5])
print(s1)
s2=pd.Series([15,25,35,45,55], index=[1,2,3,4,5])
print(s2)
s3=pd.Series([11,22,33,44,55], index=[10,20,30,40,50])
print(s3)
print(s1+s2)
print(s1*s2)
print(s2/s1)
print(s1+s3)
Vector operations on series
Series supports vectors operations. Any operation to be performed on a series
gets performed on every single element of it.
import pandas as pd
s1=pd.Series([10,20,30,40,50], index=[1,2,3,4,5])
print(s1>25) # returns booleanoutput
import pandas as pd
s1=pd.Series([10,20,30,40,50], index=[1,2,3,4,5])
print(s1[s1>25]) # print s1 only if the value of s1 is greater than 25
Modifying Elements of a Series Object
import pandas as pd
s1=pd.Series([10,20,30,40,50], index=[1,2,3,4,5])
s2=pd.Series([15,25,35,45,55], index=[1,2,3,4,5])
s1[2]=222
s2[1:4]=[1000,2000,3000]
print(s1)
print(s2)
Deleting elements from a Series
We can delete an element from a series using drop() method by passing
the index of the element to be deleted as the argument to it.
import pandas as pd
s1=pd.Series([10,20,30,40,50], index=[1,2,3,4,5])
print(s1.drop(3))
import pandas as pd
s1=pd.Series([10,20,30,40,50], index=[1,2,3,4,5])
s2=pd.Series([[15,25,34],[35,45,55]])
print(s1)
print(s2)
print(s1.dtype)
print(s2.dtype)
print(type(s1))
print(type(s2))
print(s1.shape)
print(s2.shape)
print(s1.ndim, ' ', s2.ndim)
print(s1.size,'; ',s2.size)
print(s1.empty)
print(s2.hasnans)
print(s2.count())
print(s1.nbytes,';',s2.nbytes)
Series Object Attributes
Attributes Description
Series.index Returns index of the series
Series.values Returns ndarrays
Series.dtype Returns dtype object of the underlying data
Series.shape Returns tuple of the shape of underlying data
Series.size Returns the size of the element
Series.itemsize Returns the size of the dtype
Series.hasnans Returns true if there are any NaN
Series.empty Returns true if series object is empty

Weitere ähnliche Inhalte

Ähnlich wie Python Library-Series.pptx

Python Pandas
Python PandasPython Pandas
Python Pandas
Sunil OS
 
pandasppt with informative topics coverage.pptx
pandasppt with informative topics coverage.pptxpandasppt with informative topics coverage.pptx
pandasppt with informative topics coverage.pptx
vallarasu200364
 
Unit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptxUnit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptx
prakashvs7
 
Introducing Pandas Objects.pptx
Introducing Pandas Objects.pptxIntroducing Pandas Objects.pptx
Introducing Pandas Objects.pptx
ssuser52a19e
 
4)12th_L-1_PYTHON-PANDAS-I.pptx
4)12th_L-1_PYTHON-PANDAS-I.pptx4)12th_L-1_PYTHON-PANDAS-I.pptx
4)12th_L-1_PYTHON-PANDAS-I.pptx
AdityavardhanSingh15
 
XII IP New PYTHN Python Pandas 2020-21.pptx
XII IP New PYTHN Python Pandas 2020-21.pptxXII IP New PYTHN Python Pandas 2020-21.pptx
XII IP New PYTHN Python Pandas 2020-21.pptx
lekha572836
 
DataFrame Creation.pptx
DataFrame Creation.pptxDataFrame Creation.pptx
DataFrame Creation.pptx
SarveshMariappan
 
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
 
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
 
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
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptx
ParveenShaik21
 
Pandas.pptx
Pandas.pptxPandas.pptx
Pandas.pptx
Govardhan Bhavani
 
pandas-221217084954-937bb582.pdf
pandas-221217084954-937bb582.pdfpandas-221217084954-937bb582.pdf
pandas-221217084954-937bb582.pdf
scorsam1
 
Pandas Series
Pandas SeriesPandas Series
Pandas Series
Sangita Panchal
 
ppanda.pptx
ppanda.pptxppanda.pptx
ppanda.pptx
DOLKUMARCHANDRA
 
Lecture 3 intro2data
Lecture 3 intro2dataLecture 3 intro2data
Lecture 3 intro2data
Johnson Ubah
 
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 pythonfordatascience
Pandas pythonfordatasciencePandas pythonfordatascience
Pandas pythonfordatascience
Nishant Upadhyay
 

Ähnlich wie Python Library-Series.pptx (20)

Python Pandas
Python PandasPython Pandas
Python Pandas
 
pandasppt with informative topics coverage.pptx
pandasppt with informative topics coverage.pptxpandasppt with informative topics coverage.pptx
pandasppt with informative topics coverage.pptx
 
Unit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptxUnit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptx
 
Introducing Pandas Objects.pptx
Introducing Pandas Objects.pptxIntroducing Pandas Objects.pptx
Introducing Pandas Objects.pptx
 
4)12th_L-1_PYTHON-PANDAS-I.pptx
4)12th_L-1_PYTHON-PANDAS-I.pptx4)12th_L-1_PYTHON-PANDAS-I.pptx
4)12th_L-1_PYTHON-PANDAS-I.pptx
 
XII IP New PYTHN Python Pandas 2020-21.pptx
XII IP New PYTHN Python Pandas 2020-21.pptxXII IP New PYTHN Python Pandas 2020-21.pptx
XII IP New PYTHN Python Pandas 2020-21.pptx
 
DataFrame Creation.pptx
DataFrame Creation.pptxDataFrame Creation.pptx
DataFrame Creation.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
 
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
 
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
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptx
 
Pandas.pptx
Pandas.pptxPandas.pptx
Pandas.pptx
 
pandas-221217084954-937bb582.pdf
pandas-221217084954-937bb582.pdfpandas-221217084954-937bb582.pdf
pandas-221217084954-937bb582.pdf
 
Pandas Series
Pandas SeriesPandas Series
Pandas Series
 
ppanda.pptx
ppanda.pptxppanda.pptx
ppanda.pptx
 
Lecture 3 intro2data
Lecture 3 intro2dataLecture 3 intro2data
Lecture 3 intro2data
 
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 pythonfordatascience
Pandas pythonfordatasciencePandas pythonfordatascience
Pandas pythonfordatascience
 

Kürzlich hochgeladen

Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
MichaelKnudsen27
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
HarisZaheer8
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
flufftailshop
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
SitimaJohn
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
Zilliz
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
innovationoecd
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Jeffrey Haguewood
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
alexjohnson7307
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
saastr
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
panagenda
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Tatiana Kojar
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 

Kürzlich hochgeladen (20)

Nordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptxNordic Marketo Engage User Group_June 13_ 2024.pptx
Nordic Marketo Engage User Group_June 13_ 2024.pptx
 
AWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptxAWS Cloud Cost Optimization Presentation.pptx
AWS Cloud Cost Optimization Presentation.pptx
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdfNunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
Nunit vs XUnit vs MSTest Differences Between These Unit Testing Frameworks.pdf
 
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptxOcean lotus Threat actors project by John Sitima 2024 (1).pptx
Ocean lotus Threat actors project by John Sitima 2024 (1).pptx
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
Programming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup SlidesProgramming Foundation Models with DSPy - Meetup Slides
Programming Foundation Models with DSPy - Meetup Slides
 
Presentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of GermanyPresentation of the OECD Artificial Intelligence Review of Germany
Presentation of the OECD Artificial Intelligence Review of Germany
 
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
Letter and Document Automation for Bonterra Impact Management (fka Social Sol...
 
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
leewayhertz.com-AI in predictive maintenance Use cases technologies benefits ...
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStrDeep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
Deep Dive: Getting Funded with Jason Jason Lemkin Founder & CEO @ SaaStr
 
HCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAUHCL Notes and Domino License Cost Reduction in the World of DLAU
HCL Notes and Domino License Cost Reduction in the World of DLAU
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
Skybuffer AI: Advanced Conversational and Generative AI Solution on SAP Busin...
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 

Python Library-Series.pptx

  • 1. Python Library – Pandas It is a most famous Python package for data science, which offers powerful and flexible data structures that make data analysis and manipulation easy. Pandas make data importing and data analyzing much easier. Pandas build on packages like NumPy and matplotlib to give us a single & convenient place for data analysis and visualization work. Pandas is a high level data manipulation tool developed by Wes McKinney.
  • 3. Basic Features of Panda 1. With a pandas dataframe, we can have different data types (float, int, string, datetime, etc) all in one place 2. Columns from a Panda data structure can be deleted or inserted 3. Good IO capabilities; Easily pull data from a MySQL database directly into a data frame 4. Itsupportsgroupbyoperationfordataaggregationandtransformationandalowshigh performancemergingandjoiningofdata. 5. It can easily select subsets of data from bulky datasets and even combine multiple data sets together. 6. It has the functionality to find and fill missing data. 7. Reshaping and pivoting of data sets into different forms. 8. Label-based slicing, indexing and subsetting of large data sets. 9. It allows us to apply operations to independent groups within the data. 10. It supports advanced time-series functionality( which is the use of a model to predict future values based on previously observed values. 11. It supports visualization by integrating libraries such as matplotlib, ans seaborn etc. Pandas is best at handling hugs tabular datasets comprising different data formats.
  • 4. Data Structures in Pandas A data structure is a way of storing and organizing data in a computer so that it can be accessed and worked with in an appropriate way. Important data structures of pandas are–Series,DataFrame, Panel 1. Series Series is like a one-dimensional array like structure with homogeneous data. For example, the following series is a collection of integers. Basic feature of series are  Homogeneous data  Size Immutable  Values of Data Mutable
  • 5. Pandas Series It is like one-dimensional array capable of holding data of any type (integer, string, float, python objects, etc.). Series can be created using Series() method. Any list or dictionary data can be converted into series using this method. A series can be described as an ordered dictionary with mapping of index values to data values. Create an Empty Series s1-------- series variable pd------- alternate name given to Pandas module import pandas as pd s1 = pd.Series() print(s1) Output Series([], dtype: float64) Creating Series using Series() with arguments Syntax :- pandas.Series( data, index, dtype, copy) Data supplied to Series() can be  A sequence( list)  An ndarray  A scalar value  A python dictionary  A mathematical expression or function
  • 6. Creating Series using List Like array, a list is also a one-dimensional datatype. But the difference lies in the fact that an array contains elements of same datatype, while a list may contain elements of same or different data types. Syntax :- pandas.Series( data, index = idx) import pandas as pd s1=pd.Series([10,20,30,40,50]) print(s1) *Pandas create a default index and automatically assigns the index value from 0 to 4, which is length of the list-1 import pandas as pd s1=pd.Series([10,20,30,40]) s1.index=['a', 'b', 'c', 'd'] print(s1) (or) import pandas as pd s1=pd.Series([10,20,30,40], index= ['a', 'b', 'c', 'd']) print(s1)
  • 7.
  • 8.
  • 9.
  • 11. import pandas as pd s1=pd.Series([1,2,3.3,4,7]) print(s1) * One of the element in the list, is a float value, it will convert the rest of the integer values into float and displays a float series. range() method import pandas as pd s1=pd.Series(range(4)) print(s1) Access single and multiple values based on index. import pandas as pd s1=pd.Series([2,3,5.3,7,9], index=['first','sec','third','fourth','fifth']) print(s1['sec']) Output 3.0 import pandas as pd s1=pd.Series([2,3,5.3,7,9], index=['first','sec','third','fourth','fifth']) print(s1) print(s1[['sec','third','fifth']])
  • 12. Values and index import pandas as pd s1=pd.Series([10,20,30,40,50],index=['First', 'sec', 'third', 'forth', 'fifth']) print(s1.values) import pandas as pd s1=pd.Series([10,20,30,40,50],index=['First', 'sec', 'third', 'forth','fifth']) print(s1.index) Accessing data from a Series with Position Indexing, slicing and accessing data from a series import pandas as pd s1=pd.Series([1,2,3,4,5], index=['a', 'b', 'c', 'd', 'e']) print(s1[0]) print(s1[:3]) print(s1[-3:])
  • 13. iloc and loc iloc – used for indexing or selecting based on position ie, by row number and column number. It refers to position- based indexing. Syntax iloc = [<row number range>,<column number range>] It refers to name-based loc - used for indexing or selecting based on name ie, by row name and column name. indexing. Syntax iloc = [<list of row names >,<list of column names>] import pandas as pd s1=pd.Series([1,2,3,4,5], index=['a', 'b', 'c', 'd', 'e']) print(s1.iloc[1:4]) print(s1.loc['b':'e'])
  • 14. Retrieving values from Series using head()and tail () functions Series.head() function in a series fetches first ‘n’ values from a pandas object. By default, it gives us the top 5 rows of data in the series. Series.tail() function displays the last 5 elements by default. import pandas as pd s1=pd.Series([10,20,30,40,50,60,70,80,90]) print(s1.head()) import pandas as pd s1=pd.Series([10,20,30,40,50,60,70,80,90]) print(s1.head(3)) import pandas as pd s1=pd.Series([10,20,30,40,50,60,70,80,90]) print(s1.tail(2)) Creating a Series from Scalar or Constant Values A data is a scalar value for which it is a must to provide an index. This constant value shall be repeated to match the length of the index. import pandas as pd s1=pd.Series(55, index=['a', 'b', 'c', 'd', 'e']) print(s1) Note :- here 55 is repeated for 5 times (as per no of index)
  • 15. import pandas as pd s1=pd.Series(55, index=[1,2,3,4,5]) print(s1) Using range() method import pandas as pd s1=pd.Series(40, index=range(0,4)) print(s1) import pandas as pd s1=pd.Series(40, index=range(1,6,2)) print(s1) Creating a Series with index of String (text) type String or text can be used as an index to the elements of a series. import pandas as pd s1=pd.Series('Stay Home', index=['Madhav', 'Smitha', 'Vivek']) print(s1)
  • 16. Creating a Series with range() and for loop import pandas as pd s1=pd.Series(range(1,15,3), index=[x for x in 'abcde']) print(s1) Creating a Series using two different lists * Two lists are passed as arguments to Series()method import pandas as pd months=['jan', 'feb', 'mar', 'apr', 'may'] no_days=[31,28,31,30,31] s1=pd.Series(no_days,index=months) print(s1) Creating a Series using missing values [NaN] We may need to create a series object for which size is defined but some element or data are missing. This is handled by defining NaN [Not a Number], which is an attribute of Numpy library, defining a missing value using np.NaN. import pandas as pd import numpy as np s1=pd.Series([31,28,31,np.NaN,31]) print(s1)
  • 17. Creating Series from Dictionary Using dictionary for creating a series gives us the advantage of built-in keys used as index. We do not require declaring an index as a separate list: instead, built-in keys will be treated as the index import pandas as pd data = {'a' : 0., 'b' : 1., 'c' : 2.} s = pd.Series(data) print(s) * A dictionary can be passed as input and if no index is specified, the dictionary keys are taken in the sorted order to construct index import pandas as pd1 data = {'a' : 0., 'b' : 1., 'c' : 2.} s = pd1.Series(data,index=['b','c','d','a']) print(s) import pandas as pd s1=pd.Series({'Jan':31,'Feb':28,'Mar':31,'Apr':30}) print(s1)
  • 18. Naming a series We can give a name to the two columns, index and values of a series using ‘name’ property. import pandas as pd s=pd.Series({'Jan':31,'Feb':28,'Mar':31,'Apr':30}) #naming the series and index s.name='Days' s.index.name='Month' print(s) * The index column is assigned the name ‘Month’ and data is assigned the name ‘Days’ Creating a Series using a mathematical expression/function import pandas as pd import numpy as np s1=np.arange(5,10) print(s1) s2=pd.Series(index=s1,data=s1*4) print(s2)
  • 19. import pandas as pd import numpy as np s1=np.arange(5,10) print(s1) s2=pd.Series(index=s1,data=s1**4) print(s2) Mathematical operation on series import pandas as pd s1=pd.Series([10,20,30,40,50], index=[1,2,3,4,5]) print(s1) s2=pd.Series([15,25,35,45,55], index=[1,2,3,4,5]) print(s2) s3=pd.Series([11,22,33,44,55], index=[10,20,30,40,50]) print(s3) print(s1+s2) print(s1*s2) print(s2/s1) print(s1+s3)
  • 20. Vector operations on series Series supports vectors operations. Any operation to be performed on a series gets performed on every single element of it. import pandas as pd s1=pd.Series([10,20,30,40,50], index=[1,2,3,4,5]) print(s1>25) # returns booleanoutput import pandas as pd s1=pd.Series([10,20,30,40,50], index=[1,2,3,4,5]) print(s1[s1>25]) # print s1 only if the value of s1 is greater than 25 Modifying Elements of a Series Object import pandas as pd s1=pd.Series([10,20,30,40,50], index=[1,2,3,4,5]) s2=pd.Series([15,25,35,45,55], index=[1,2,3,4,5]) s1[2]=222 s2[1:4]=[1000,2000,3000] print(s1) print(s2)
  • 21. Deleting elements from a Series We can delete an element from a series using drop() method by passing the index of the element to be deleted as the argument to it. import pandas as pd s1=pd.Series([10,20,30,40,50], index=[1,2,3,4,5]) print(s1.drop(3)) import pandas as pd s1=pd.Series([10,20,30,40,50], index=[1,2,3,4,5]) s2=pd.Series([[15,25,34],[35,45,55]]) print(s1) print(s2) print(s1.dtype) print(s2.dtype) print(type(s1)) print(type(s2)) print(s1.shape) print(s2.shape) print(s1.ndim, ' ', s2.ndim) print(s1.size,'; ',s2.size) print(s1.empty) print(s2.hasnans) print(s2.count()) print(s1.nbytes,';',s2.nbytes)
  • 22. Series Object Attributes Attributes Description Series.index Returns index of the series Series.values Returns ndarrays Series.dtype Returns dtype object of the underlying data Series.shape Returns tuple of the shape of underlying data Series.size Returns the size of the element Series.itemsize Returns the size of the dtype Series.hasnans Returns true if there are any NaN Series.empty Returns true if series object is empty