Program: Pie Chart
from matplotlib import pyplot as plt
# Data for pie chart
cars = ['AUDI', 'BMW', 'FORD', 'TESLA', 'JAGUAR', 'MERCEDES']
data = [23, 17, 35, 29, 12, 4]
# Create a figure
fig = [Link](figsize=(10, 7))
# Create pie chart
[Link](data, labels=cars)
Scatter Plot Program
# Show chart
[Link]()
1. labels – Names for each slice in the pie chart
2. sizes – Values (numbers) that decide the size of each slice
3. colors – List of colors used to fill the slices
4. shadow – Adds a shadow behind the pie chart
5. startangle – Rotates the pie chart; tells where the first slice starts (default is 0 degree at
the right side, then moves anticlockwise)
Programs for Each Attribute
1. labels
import [Link] as plt
sizes = [20, 30, 50]
labels = ["Math", "Science", "English"]
[Link](sizes, labels=labels)
[Link]()
2. sizes
import [Link] as plt
sizes = [10, 40, 50]
labels = ["English", "Math", "Science"]
[Link](sizes, labels=labels)
[Link]()
3. colors
import [Link] as plt
sizes = [30, 40, 30]
labels = ["A", "B", "C"]
colors = ["red", "green", "blue"]
[Link](sizes, labels=labels, colors=colors)
[Link]()
4. shadow
import [Link] as plt
sizes = [25, 35, 40]
labels = ["X", "Y", "Z"]
[Link](sizes, labels=labels, shadow=True)
[Link]()
5. startangle
import [Link] as plt
sizes = [20, 30, 50]
labels = ["Red", "Blue", "Yellow"]
[Link](sizes, labels=labels, startangle=90)
[Link]()
Scatter Plot Program
import [Link] as plt
# Data for scatter plot
x = [5, 7, 8, 7, 2, 17, 2, 9, 4, 11, 12, 9, 6]
y = [99, 86, 87, 88, 100, 86, 103, 87, 94, 78, 77, 85, 86]
# Create scatter plot
[Link](x, y, c="blue") # c="blue" means points will be blue
# Show plot
[Link]()
What is Pandas
Pandas is a Python library used for working with data in tables (like Excel).
It makes data easy to read, clean, analyze, and visualize.
It uses DataFrame (rows and columns) and Series (single column).
Advantages of Using Pandas
1. Data Manipulation
We can easily add, delete, or change data.
Example:
import pandas as pd
2. Data Analysis
We can find sum, mean, max, etc. very quickly
3. Integration
Works well with other libraries like NumPy and Matplotlib.
4. Flexibility
Can handle different types of data (numbers, text, dates).
Visualization
We can easily make graphs and charts.
Summary
Pandas is like Excel in Python.
It is easy to use for reading, cleaning, analyzing, and showing data.
It becomes very powerful when combined with NumPy and Matplotlib.
What is a Series in Pandas
• A Series is like a single column of data in Pandas.
• It has two parts:
1. Values → the actual data
2. Index → labels for each value (default is 0,1,2,…)
Is Pandas built-in or third-party?
• Pandas is a third-party library.
• This means it does not come built-in with Python.
• You must install it separately before using it.
How to Install Pandas
Step 1: Open Command Prompt (Windows) or Terminal (Mac/Linux).
Step 2: Type this command and press Enter:
pip install pandas
Creating a Series
Example 1 – Simple Series
import pandas as pd
series1 = [Link]([10, 20, 30])
print(series1)
Output
0 10
1 20
2 30
Explanation: Values are 10,20,30 and indexes are 0,1,2 by default.
Example 2 – Series with Custom Index
import pandas as pd
s = [Link]([11, 8, 6, 14, 25], index=['a','b','c','d','e'])
print(s)
Output
a 11
b 8
c 6
d 14
e 25
Explanation: Now indexes are a,b,c,d,e instead of numbers.
Example 3 – Series from NumPy Array
import pandas as pd
import numpy as np
data = [Link](['a','b','c','d','e'])
s = [Link](data)
print(s)
Output
0 a
1 b
2 c
3 d
4 e
Explanation: Values come from NumPy array, default indexes 0 to 4.
Summary
• Series = one column of data with index.
• Default index starts from 0, but we can also give custom index.
• We can create a Series from list, NumPy array, or dictionary.