SlideShare a Scribd company logo
1 of 13
Pandas in Series and Data
frame
Dr.R.SUNDAR
CSE DEPT
MITS
pandas in Series and data frame
• In pandas, the primary data structure used to store and manipulate data is called
a "DataFrame."
• A DataFrame is a two-dimensional, tabular data structure with labeled axes (rows
and columns). It is similar to a spreadsheet or a SQL table.
• Each column in a DataFrame can have a different data type, and you can perform
various operations like filtering, grouping, aggregation, and more on the data
stored in a DataFrame.
• Pandas also provides another data structure called a "Series," which is essentially
a one-dimensional array-like object but with an associated index.
• Series can be thought of as a single column of a DataFrame.
• These data structures, DataFrame and Series, are powerful tools for data
manipulation and analysis in Python, and they are an essential part of the pandas
library.
Python Pandas Series
1.import pandas as pd
• # a simple char list
• list = ['g', 'e', 'e', 'k', 's']
• # create series form a char list
• res = pd.Series(list)
• print(res)
2.import pandas as pd
• # a simple int list
• list = [1,2,3,4,5]
• # create series form a int list
• res = pd.Series(list)
• print(res)
pandas in Series and data frame
3.import pandas as pd
• dic = { 'Id': 1013, 'Name': 'MOhe',
'State': 'Maniput','Age': 24}
• res = pd.Series(dic)
• print(res)
4.import pandas as pd
• # list of strings
• lst = [‘python', 'For', ‘series', ‘and',
• ‘Dataframe', ‘is', ‘object']
• # Calling DataFrame constructor on list
• df = pd.DataFrame(lst)
• display(df)
pandas in Series and data frame
• import pandas as pd
• # initialise data of lists.
• data = {'Name':['Tom', 'nick', 'krish', 'jack'],
'Age':[20, 21, 19, 18]}
• # Create DataFrame
• df = pd.DataFrame(data)
• display(df)
pandas in Series and data frame
• import pandas as pd
• # Define a dictionary containing employee data
• data = {'Name':['Jai', 'Princi', 'Gaurav', 'Anuj'],
• 'Age':[27, 24, 22, 32],
• 'Address':['Delhi', 'Kanpur', 'Allahabad', 'Kannauj'],
• 'Qualification':['Msc', 'MA', 'MCA', 'Phd']}
• # Convert the dictionary into DataFrame
• df = pd.DataFrame(data)
• # select two columns
• print(df[['Name', 'Qualification']])
pandas in Series and data frame
• from pandas import DataFrame
• # Creating a data frame
• Data = {'Name': ['Mohe', 'Shyni', 'Parul', 'Sam'],
• 'ID': [12, 43, 54, 32],
• 'Place': ['Delhi', 'Kochi', 'Pune', 'Patna']
• df = DataFrame(Data, columns = ['Name', 'ID', 'Place'])
• # Print original data frame
• print("Original data frame:n")
• display(df)
• # Selecting the product of Electronic Type
• select_prod = df.loc[df['Name'] == 'Mohe']
• print("n")
• # Print selected rows based on the condition
• print("Selecting rows:n")
• display (select_prod)
pandas in Series and data frame
• from pandas import DataFrame
• # Creating a data frame
• Data = {'Name': ['Mohe', 'Shyni', 'Parul', 'Sam'],
• 'ID': [12, 43, 54, 32],
• 'Place': ['Delhi', 'Kochi', 'Pune', 'Patna']
• }
• df = DataFrame(Data, columns = ['Name', 'ID', 'Place'])
• # Print original data frame
• print("Original data frame:")
• display(df)
• print("Selected column: ")
• display(df[['Name', 'ID']] )
Indexing & Selecting & Filtering in Pandas
• import numpy as np
• import pandas as pd
• obj=pd.Series(np.arange(5),index=['a','b','c','d','f'])
• obj
• Working with Index in Series
• obj['c']
• entering the index number in square brackets.
• obj[2]
• slice the data.
• Obj[0:3]
• Selecting in Series
• select the specific rows.
• Obj[[‘a’,’c’]]
• Selecting the index number.
• Obj[[0,2]]
• Filtering in Series
• Obj[obj<2]---------values less than 2.
• Slice the values
• Obj[‘a’:’c’]
• Assign a value of sliced piece.
• Obj[‘b’:’c’]=5
• obj
Selecting in DataFrame
• how to index in DataFrame, let me create a DataFrame.
• data=pd.DataFrame(np.arange(16).reshape(4,4),
index=['London','Paris','Berlin','India'],
columns=['one','two','three','four'])
• Data
The column named two
• data['two']
• select more than one column
• data[['one','two']]
• slice the rows.
• data[:3]
Filtering in DataFrame
• data[data['four']>5]
• Assign data to specific values.
data[data<5]=0
data
Selecting with iloc and loc methods
The iloc method to select a row using the row’s index.
data.iloc[1]
select the specific columns of the row
data.iloc[1,[1,2,3]]
select specific columns of multiple rows
data.iloc[[1,3],[1,2,3]]
Filtering in DataFrame
• loc method need to use names for loc.
• data.loc['Paris',['one','two']]
• data.loc[:'Paris','four']

More Related Content

Similar to Pandas Series and DataFrames

DATA-Analysis-All-Slidescoursera.pdf
DATA-Analysis-All-Slidescoursera.pdfDATA-Analysis-All-Slidescoursera.pdf
DATA-Analysis-All-Slidescoursera.pdfNamanKabadi1
 
B-6vdzrQSgaur3c60LoG1g_d0201f1ecaa148ca9ce77f6e15a62643_Data-Analysis-All-Sli...
B-6vdzrQSgaur3c60LoG1g_d0201f1ecaa148ca9ce77f6e15a62643_Data-Analysis-All-Sli...B-6vdzrQSgaur3c60LoG1g_d0201f1ecaa148ca9ce77f6e15a62643_Data-Analysis-All-Sli...
B-6vdzrQSgaur3c60LoG1g_d0201f1ecaa148ca9ce77f6e15a62643_Data-Analysis-All-Sli...poojagupta010
 
Unit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptxUnit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptxprakashvs7
 
Python Pandas.pptx
Python Pandas.pptxPython Pandas.pptx
Python Pandas.pptxSujayaBiju
 
Pandas-(Ziad).pptx
Pandas-(Ziad).pptxPandas-(Ziad).pptx
Pandas-(Ziad).pptxSivam Chinna
 
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
 
Introducing Pandas Objects.pptx
Introducing Pandas Objects.pptxIntroducing Pandas Objects.pptx
Introducing Pandas Objects.pptxssuser52a19e
 
Presentation on Pandas in _ detail .pptx
Presentation on Pandas in _ detail .pptxPresentation on Pandas in _ detail .pptx
Presentation on Pandas in _ detail .pptx16115yogendraSingh
 
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
 
pandas dataframe notes.pdf
pandas dataframe notes.pdfpandas dataframe notes.pdf
pandas dataframe notes.pdfAjeshSurejan2
 
Meetup Junio Data Analysis with python 2018
Meetup Junio Data Analysis with python 2018Meetup Junio Data Analysis with python 2018
Meetup Junio Data Analysis with python 2018DataLab Community
 
Python Library-Series.pptx
Python Library-Series.pptxPython Library-Series.pptx
Python Library-Series.pptxJustinDsouza12
 
Getting started with Pandas Cheatsheet.pdf
Getting started with Pandas Cheatsheet.pdfGetting started with Pandas Cheatsheet.pdf
Getting started with Pandas Cheatsheet.pdfSudhakarVenkey
 

Similar to Pandas Series and DataFrames (20)

DataFrame Creation.pptx
DataFrame Creation.pptxDataFrame Creation.pptx
DataFrame Creation.pptx
 
DATA-Analysis-All-Slidescoursera.pdf
DATA-Analysis-All-Slidescoursera.pdfDATA-Analysis-All-Slidescoursera.pdf
DATA-Analysis-All-Slidescoursera.pdf
 
B-6vdzrQSgaur3c60LoG1g_d0201f1ecaa148ca9ce77f6e15a62643_Data-Analysis-All-Sli...
B-6vdzrQSgaur3c60LoG1g_d0201f1ecaa148ca9ce77f6e15a62643_Data-Analysis-All-Sli...B-6vdzrQSgaur3c60LoG1g_d0201f1ecaa148ca9ce77f6e15a62643_Data-Analysis-All-Sli...
B-6vdzrQSgaur3c60LoG1g_d0201f1ecaa148ca9ce77f6e15a62643_Data-Analysis-All-Sli...
 
Unit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptxUnit 3_Numpy_Vsp.pptx
Unit 3_Numpy_Vsp.pptx
 
Python Pandas.pptx
Python Pandas.pptxPython Pandas.pptx
Python Pandas.pptx
 
Pandas-(Ziad).pptx
Pandas-(Ziad).pptxPandas-(Ziad).pptx
Pandas-(Ziad).pptx
 
Pandas pythonfordatascience
Pandas pythonfordatasciencePandas pythonfordatascience
Pandas pythonfordatascience
 
2 pandasbasic
2 pandasbasic2 pandasbasic
2 pandasbasic
 
Unit 3_Numpy_VP.pptx
Unit 3_Numpy_VP.pptxUnit 3_Numpy_VP.pptx
Unit 3_Numpy_VP.pptx
 
Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet Python Pandas for Data Science cheatsheet
Python Pandas for Data Science cheatsheet
 
Introducing Pandas Objects.pptx
Introducing Pandas Objects.pptxIntroducing Pandas Objects.pptx
Introducing Pandas Objects.pptx
 
Presentation on Pandas in _ detail .pptx
Presentation on Pandas in _ detail .pptxPresentation on Pandas in _ detail .pptx
Presentation on Pandas in _ detail .pptx
 
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
 
Pa2 session 2
Pa2 session 2Pa2 session 2
Pa2 session 2
 
pandas dataframe notes.pdf
pandas dataframe notes.pdfpandas dataframe notes.pdf
pandas dataframe notes.pdf
 
PANDAS DATAFRAME.pdf
PANDAS DATAFRAME.pdfPANDAS DATAFRAME.pdf
PANDAS DATAFRAME.pdf
 
Meetup Junio Data Analysis with python 2018
Meetup Junio Data Analysis with python 2018Meetup Junio Data Analysis with python 2018
Meetup Junio Data Analysis with python 2018
 
Python Library-Series.pptx
Python Library-Series.pptxPython Library-Series.pptx
Python Library-Series.pptx
 
Lecture 9.pptx
Lecture 9.pptxLecture 9.pptx
Lecture 9.pptx
 
Getting started with Pandas Cheatsheet.pdf
Getting started with Pandas Cheatsheet.pdfGetting started with Pandas Cheatsheet.pdf
Getting started with Pandas Cheatsheet.pdf
 

Recently uploaded

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 

Recently uploaded (20)

Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 

Pandas Series and DataFrames

  • 1. Pandas in Series and Data frame Dr.R.SUNDAR CSE DEPT MITS
  • 2. pandas in Series and data frame • In pandas, the primary data structure used to store and manipulate data is called a "DataFrame." • A DataFrame is a two-dimensional, tabular data structure with labeled axes (rows and columns). It is similar to a spreadsheet or a SQL table. • Each column in a DataFrame can have a different data type, and you can perform various operations like filtering, grouping, aggregation, and more on the data stored in a DataFrame. • Pandas also provides another data structure called a "Series," which is essentially a one-dimensional array-like object but with an associated index. • Series can be thought of as a single column of a DataFrame. • These data structures, DataFrame and Series, are powerful tools for data manipulation and analysis in Python, and they are an essential part of the pandas library.
  • 3. Python Pandas Series 1.import pandas as pd • # a simple char list • list = ['g', 'e', 'e', 'k', 's'] • # create series form a char list • res = pd.Series(list) • print(res) 2.import pandas as pd • # a simple int list • list = [1,2,3,4,5] • # create series form a int list • res = pd.Series(list) • print(res)
  • 4. pandas in Series and data frame 3.import pandas as pd • dic = { 'Id': 1013, 'Name': 'MOhe', 'State': 'Maniput','Age': 24} • res = pd.Series(dic) • print(res) 4.import pandas as pd • # list of strings • lst = [‘python', 'For', ‘series', ‘and', • ‘Dataframe', ‘is', ‘object'] • # Calling DataFrame constructor on list • df = pd.DataFrame(lst) • display(df)
  • 5. pandas in Series and data frame • import pandas as pd • # initialise data of lists. • data = {'Name':['Tom', 'nick', 'krish', 'jack'], 'Age':[20, 21, 19, 18]} • # Create DataFrame • df = pd.DataFrame(data) • display(df)
  • 6. pandas in Series and data frame • import pandas as pd • # Define a dictionary containing employee data • data = {'Name':['Jai', 'Princi', 'Gaurav', 'Anuj'], • 'Age':[27, 24, 22, 32], • 'Address':['Delhi', 'Kanpur', 'Allahabad', 'Kannauj'], • 'Qualification':['Msc', 'MA', 'MCA', 'Phd']} • # Convert the dictionary into DataFrame • df = pd.DataFrame(data) • # select two columns • print(df[['Name', 'Qualification']])
  • 7. pandas in Series and data frame • from pandas import DataFrame • # Creating a data frame • Data = {'Name': ['Mohe', 'Shyni', 'Parul', 'Sam'], • 'ID': [12, 43, 54, 32], • 'Place': ['Delhi', 'Kochi', 'Pune', 'Patna'] • df = DataFrame(Data, columns = ['Name', 'ID', 'Place']) • # Print original data frame • print("Original data frame:n") • display(df) • # Selecting the product of Electronic Type • select_prod = df.loc[df['Name'] == 'Mohe'] • print("n") • # Print selected rows based on the condition • print("Selecting rows:n") • display (select_prod)
  • 8. pandas in Series and data frame • from pandas import DataFrame • # Creating a data frame • Data = {'Name': ['Mohe', 'Shyni', 'Parul', 'Sam'], • 'ID': [12, 43, 54, 32], • 'Place': ['Delhi', 'Kochi', 'Pune', 'Patna'] • } • df = DataFrame(Data, columns = ['Name', 'ID', 'Place']) • # Print original data frame • print("Original data frame:") • display(df) • print("Selected column: ") • display(df[['Name', 'ID']] )
  • 9. Indexing & Selecting & Filtering in Pandas • import numpy as np • import pandas as pd • obj=pd.Series(np.arange(5),index=['a','b','c','d','f']) • obj • Working with Index in Series • obj['c'] • entering the index number in square brackets. • obj[2] • slice the data. • Obj[0:3] • Selecting in Series • select the specific rows. • Obj[[‘a’,’c’]] • Selecting the index number. • Obj[[0,2]]
  • 10. • Filtering in Series • Obj[obj<2]---------values less than 2. • Slice the values • Obj[‘a’:’c’] • Assign a value of sliced piece. • Obj[‘b’:’c’]=5 • obj
  • 11. Selecting in DataFrame • how to index in DataFrame, let me create a DataFrame. • data=pd.DataFrame(np.arange(16).reshape(4,4), index=['London','Paris','Berlin','India'], columns=['one','two','three','four']) • Data The column named two • data['two'] • select more than one column • data[['one','two']] • slice the rows. • data[:3]
  • 12. Filtering in DataFrame • data[data['four']>5] • Assign data to specific values. data[data<5]=0 data Selecting with iloc and loc methods The iloc method to select a row using the row’s index. data.iloc[1] select the specific columns of the row data.iloc[1,[1,2,3]] select specific columns of multiple rows data.iloc[[1,3],[1,2,3]]
  • 13. Filtering in DataFrame • loc method need to use names for loc. • data.loc['Paris',['one','two']] • data.loc[:'Paris','four']