SlideShare a Scribd company logo
1 of 17
Download to read offline
Decision Making Tools
Pandas
● Pandas is an open-source library that is built on top of NumPy library.
● It is a Python package that offers various data structures and operations for
manipulating numerical data and time series.
● It is mainly popular for importing and analyzing data much easier.
● Pandas is fast and it has high-performance & productivity for users.
Installation
● The first step of working in pandas is to ensure whether it is installed in the Python
folder or not.
● If not then we need to install it in our system using pip command.
● Command:
○ pip install pandas
● After the pandas have been installed into the system, you need to import the library.
○ import pandas as pd
Pandas
● Pandas generally provide two data structures for manipulating data,
They are:
○ Series
○ DataFrame
Series
● Pandas Series is a one-dimensional labeled array capable of holding data of any type
(integer, string, float, python objects, etc.).
● The axis labels are collectively called indexes.
● Pandas Series is nothing but a column in an excel sheet.
Creating a series
● In the real world, a Pandas Series will be
created by loading the datasets from
existing storage, storage can be SQL
Database, CSV file, an Excel file.
● Pandas Series can be created from the
lists, dictionary, and from a scalar value
etc.
import pandas as pd
import numpy as np
# Creating empty series
ser = pd.Series()
print(ser)
# simple array
data = np.array(['s', 'e', 'r', 'i', 'e', 's'])
ser = pd.Series(data)
print(ser)
Creating a series from lists
● In order to create a series from list, we
have to first create a list after that we
can create a series from list.
import pandas as pd
# a simple list
list = ['s', 'e', 'r', 'i', 'e', 's']
# create series from a list
ser = pd.Series(list)
print(ser)
Accessing element of Series
There are two ways through which we can access element of series, they are :
● Accessing Element from Series with Position
● Accessing Element Using Label (index)
Accessing Element from Series with Position :
● In order to access the series element refers to the index number.
● Use the index operator [ ] to access an element in a series.
● The index must be an integer. In order to access multiple elements from a series,
we use Slice operation.
Example
# import pandas and numpy
import pandas as pd
import numpy as np
# creating simple array
data = np.array(['s','e','r','i','e','s',
'i','n','P','y','t','h','o','n'])
ser = pd.Series(data)
#retrieve the first element
print(ser[:5])
Accessing Element Using Label (index)
● In order to access an element from
series, we have to set values by index
label.
● A Series is like a fixed-size dictionary
in that you can get and set values by
index label.
import pandas as pd
import numpy as np
# creating simple array
data = np.array(['s','e','r','i','e','s', 'i','n','P','y','t','h','o','n'])
ser
=pd.Series(data,index=[10,11,12,13,14,15,16,17,18,
19,20,21,22,23])
# accessing a element using index element
print(ser[16])
Indexing and Selecting Data in Series
● Indexing in pandas means simply selecting
particular data from a Series.
● Indexing could mean selecting all the data,
some of the data from particular columns.
Indexing can also be known as Subset
Selection.
import pandas as pd
# making data frame
df =
pd.read_csv("/Users/maik/Documents/DCSE/Courses
/IMS/DMT/nba.csv")
ser = pd.Series(df['Name'])
data = ser.head(10)
data
Data Frames
● A Pandas DataFrame is a 2 dimensional
data structure, like a 2 dimensional
array, or a table with rows and columns.
import pandas as pd
data = {
"calories": [420, 380, 390],
"duration": [50, 40, 45] }
#load data into a DataFrame object:
df = pd.DataFrame(data)
print(df)
Locate Row
● As you can see from the result above, the DataFrame is like a table with rows and columns.
● Pandas use the loc attribute to return one or more specified row(s).
○ print(df.loc[0])
○ print(df.loc[[0, 1]])
Named Indexes
● With the index argument, you can name your own indexes.
import pandas as pd
data = {
"calories": [420, 380, 390],
"duration": [50, 40, 45]
}
df = pd.DataFrame(data, index = ["day1", "day2", "day3"])
print(df)
Locate Named Indexes
● Use the named index in the loc attribute to return the specified row(s).
○ print(df.loc["day2"])
Note: use to_string() to print the entire DataFrame.
Example
import pandas as pd
# reading csv file
data =
pd.read_csv("/Users/maik/Documents/DCSE/Co
urses/IMS/DMT/nba.csv")
# storing dtype before converting
before = data.dtypes
# converting dtypes using astype
data["Salary"]= data["Salary"].astype(int)
data["Number"]= data["Number"].astype(str)
# storing dtype after converting
after = data.dtypes
# printing to compare
print("BEFORE CONVERSIONn", before, "n")
print("AFTER CONVERSIONn", after, "n")
Output

More Related Content

Similar to Lecture on Python Pandas for Decision Making

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
 
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
 
b09e9e67-aeb9-460b-9f96-cfccb318d3a7.pptx
b09e9e67-aeb9-460b-9f96-cfccb318d3a7.pptxb09e9e67-aeb9-460b-9f96-cfccb318d3a7.pptx
b09e9e67-aeb9-460b-9f96-cfccb318d3a7.pptx
UtsabDas8
 
pandas for series and dataframe.pptx
pandas for series and dataframe.pptxpandas for series and dataframe.pptx
pandas for series and dataframe.pptx
ssuser52a19e
 
Introducing Pandas Objects.pptx
Introducing Pandas Objects.pptxIntroducing Pandas Objects.pptx
Introducing Pandas Objects.pptx
ssuser52a19e
 

Similar to Lecture on Python Pandas for Decision Making (20)

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
 
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
 
Pandas-(Ziad).pptx
Pandas-(Ziad).pptxPandas-(Ziad).pptx
Pandas-(Ziad).pptx
 
Python-for-Data-Analysis.pptx
Python-for-Data-Analysis.pptxPython-for-Data-Analysis.pptx
Python-for-Data-Analysis.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
 
Python Pandas.pptx
Python Pandas.pptxPython Pandas.pptx
Python Pandas.pptx
 
b09e9e67-aeb9-460b-9f96-cfccb318d3a7.pptx
b09e9e67-aeb9-460b-9f96-cfccb318d3a7.pptxb09e9e67-aeb9-460b-9f96-cfccb318d3a7.pptx
b09e9e67-aeb9-460b-9f96-cfccb318d3a7.pptx
 
pandas for series and dataframe.pptx
pandas for series and dataframe.pptxpandas for series and dataframe.pptx
pandas for series and dataframe.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
 
Lecture 9.pptx
Lecture 9.pptxLecture 9.pptx
Lecture 9.pptx
 
Aggregate.pptx
Aggregate.pptxAggregate.pptx
Aggregate.pptx
 
Lecture 3 intro2data
Lecture 3 intro2dataLecture 3 intro2data
Lecture 3 intro2data
 
DataFrame Creation.pptx
DataFrame Creation.pptxDataFrame Creation.pptx
DataFrame Creation.pptx
 
ppanda.pptx
ppanda.pptxppanda.pptx
ppanda.pptx
 
PYTHON PANDAS.pptx
PYTHON PANDAS.pptxPYTHON PANDAS.pptx
PYTHON PANDAS.pptx
 
phgv.pptx.pptx
phgv.pptx.pptxphgv.pptx.pptx
phgv.pptx.pptx
 
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
 
Introducing Pandas Objects.pptx
Introducing Pandas Objects.pptxIntroducing Pandas Objects.pptx
Introducing Pandas Objects.pptx
 
interenship.pptx
interenship.pptxinterenship.pptx
interenship.pptx
 

Recently uploaded

Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Recently uploaded (20)

TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 

Lecture on Python Pandas for Decision Making

  • 2. Pandas ● Pandas is an open-source library that is built on top of NumPy library. ● It is a Python package that offers various data structures and operations for manipulating numerical data and time series. ● It is mainly popular for importing and analyzing data much easier. ● Pandas is fast and it has high-performance & productivity for users.
  • 3. Installation ● The first step of working in pandas is to ensure whether it is installed in the Python folder or not. ● If not then we need to install it in our system using pip command. ● Command: ○ pip install pandas ● After the pandas have been installed into the system, you need to import the library. ○ import pandas as pd
  • 4. Pandas ● Pandas generally provide two data structures for manipulating data, They are: ○ Series ○ DataFrame
  • 5. Series ● Pandas Series is a one-dimensional labeled array capable of holding data of any type (integer, string, float, python objects, etc.). ● The axis labels are collectively called indexes. ● Pandas Series is nothing but a column in an excel sheet.
  • 6. Creating a series ● In the real world, a Pandas Series will be created by loading the datasets from existing storage, storage can be SQL Database, CSV file, an Excel file. ● Pandas Series can be created from the lists, dictionary, and from a scalar value etc. import pandas as pd import numpy as np # Creating empty series ser = pd.Series() print(ser) # simple array data = np.array(['s', 'e', 'r', 'i', 'e', 's']) ser = pd.Series(data) print(ser)
  • 7. Creating a series from lists ● In order to create a series from list, we have to first create a list after that we can create a series from list. import pandas as pd # a simple list list = ['s', 'e', 'r', 'i', 'e', 's'] # create series from a list ser = pd.Series(list) print(ser)
  • 8. Accessing element of Series There are two ways through which we can access element of series, they are : ● Accessing Element from Series with Position ● Accessing Element Using Label (index) Accessing Element from Series with Position : ● In order to access the series element refers to the index number. ● Use the index operator [ ] to access an element in a series. ● The index must be an integer. In order to access multiple elements from a series, we use Slice operation.
  • 9. Example # import pandas and numpy import pandas as pd import numpy as np # creating simple array data = np.array(['s','e','r','i','e','s', 'i','n','P','y','t','h','o','n']) ser = pd.Series(data) #retrieve the first element print(ser[:5])
  • 10. Accessing Element Using Label (index) ● In order to access an element from series, we have to set values by index label. ● A Series is like a fixed-size dictionary in that you can get and set values by index label. import pandas as pd import numpy as np # creating simple array data = np.array(['s','e','r','i','e','s', 'i','n','P','y','t','h','o','n']) ser =pd.Series(data,index=[10,11,12,13,14,15,16,17,18, 19,20,21,22,23]) # accessing a element using index element print(ser[16])
  • 11. Indexing and Selecting Data in Series ● Indexing in pandas means simply selecting particular data from a Series. ● Indexing could mean selecting all the data, some of the data from particular columns. Indexing can also be known as Subset Selection. import pandas as pd # making data frame df = pd.read_csv("/Users/maik/Documents/DCSE/Courses /IMS/DMT/nba.csv") ser = pd.Series(df['Name']) data = ser.head(10) data
  • 12. Data Frames ● A Pandas DataFrame is a 2 dimensional data structure, like a 2 dimensional array, or a table with rows and columns. import pandas as pd data = { "calories": [420, 380, 390], "duration": [50, 40, 45] } #load data into a DataFrame object: df = pd.DataFrame(data) print(df)
  • 13. Locate Row ● As you can see from the result above, the DataFrame is like a table with rows and columns. ● Pandas use the loc attribute to return one or more specified row(s). ○ print(df.loc[0]) ○ print(df.loc[[0, 1]])
  • 14. Named Indexes ● With the index argument, you can name your own indexes. import pandas as pd data = { "calories": [420, 380, 390], "duration": [50, 40, 45] } df = pd.DataFrame(data, index = ["day1", "day2", "day3"]) print(df)
  • 15. Locate Named Indexes ● Use the named index in the loc attribute to return the specified row(s). ○ print(df.loc["day2"]) Note: use to_string() to print the entire DataFrame.
  • 16. Example import pandas as pd # reading csv file data = pd.read_csv("/Users/maik/Documents/DCSE/Co urses/IMS/DMT/nba.csv") # storing dtype before converting before = data.dtypes # converting dtypes using astype data["Salary"]= data["Salary"].astype(int) data["Number"]= data["Number"].astype(str) # storing dtype after converting after = data.dtypes # printing to compare print("BEFORE CONVERSIONn", before, "n") print("AFTER CONVERSIONn", after, "n")