Python Pandas Chapter 1 (Pages 1-18) - Important Notes, Solved Examples, Theory Questions
and Programs
1. Introduction to Pandas
- Pandas is a Python library used for data analysis and manipulation.
- It provides fast and easy data handling using Series and DataFrame.
- It is built on NumPy.
- Data can be loaded from CSV, Excel and other sources.
2. Important Features of Pandas
- Handles missing data.
- Easy indexing and filtering.
- Data cleaning and transformation.
- Supports mathematical and statistical operations.
3. Pandas Data Structures
A) Series:
- One dimensional labelled array.
- Stores data with index values.
Example:
import pandas as pd
s = [Link]([10,20,30])
print(s)
Output:
0 10
1 20
2 30
B) DataFrame:
- Two dimensional table with rows and columns.
Example:
data = {'Name':['A','B'], 'Marks':[80,90]}
df = [Link](data)
print(df)
4. Pandas Installation and Import
pip install pandas
import pandas as pd
5. Creating Series
Example:
[Link]([5,10,15], index=['a','b','c'])
Access:
series['a']
6. Creating DataFrame
Example:
df = [Link]({'A':[1,2], 'B':[3,4]})
7. Data Selection
loc:
Used for label based selection.
Example:
[Link][0]
iloc:
Used for position based selection.
Example:
[Link][0]
8. Important Topic Explanation
1.4.4 DataFrame:
A DataFrame is a two-dimensional labelled data structure.
It contains rows and columns like an Excel table.
Each column can contain different data types.
Example:
Student = {
'Name':['Rahul','Riya'],
'Age':[20,21]
}
df = [Link](Student)
print(df)
1.4.5 Accessing DataFrame Elements:
Data can be accessed using:
- Column name
- loc[]
- iloc[]
Example:
df['Name']
[Link][0]
[Link][1]
9. Exercise Theory Questions with Answers
Q1. What is Pandas?
Ans: Pandas is a Python library for data analysis and data manipulation.
Q2. Difference between Series and DataFrame?
Ans:
Series is one dimensional.
DataFrame is two dimensional.
Q3. What is DataFrame?
Ans:
A table like structure containing rows and columns.
10. Programming Questions with Solutions
Program 1:
Create a Series.
Solution:
import pandas as pd
s=[Link]([1,2,3,4])
print(s)
Program 2:
Create DataFrame.
Solution:
import pandas as pd
df=[Link]({'Math':[90,80],'Science':[85,95]})
print(df)
Program 3:
Access first row.
Solution:
print([Link][0])
Important Revision Points:
- Pandas = Data Analysis library
- Series = 1D data
- DataFrame = 2D data
- loc = label based
- iloc = index based
- Import pandas using: import pandas as pd