MUSKAN RAJPUT 10323210071
EXPERIMENT-10
AIM: Create histograms and scatter plots for basic exploratory data analysis.
OBJECTIVE: Here are the objectives for manipulating pandas Series and DataFrames,
1. Install pandas: Ensure pandas library is installed in your Python environment.
2. Import pandas: Import the pandas library using import pandas as pd.
[Link] Series: Create a pandas Series and perform operations like indexing, slicing, and
modifying data.
4. Create DataFrame: Create a pandas DataFrame and perform operations like
indexing, slicing, adding, removing, and modifying data.
5. Manipulate Data: Conduct data manipulations such as selecting, filtering,
adding/removing rows and columns, and applying functions.
[Link] Results: Print the Series and DataFrames along with the results of the operations
to verify correctness.
ALGORITHM:
Step 1: Install Required Libraries
1. Ensure the necessary libraries are installed:
o Install pandas for data manipulation. o Install matplotlib and seaborn for
data visualization. o Use pip to install these libraries if not already
installed.
Step 2: Import Libraries
1. Import the necessary libraries:
o Import pandas for data handling.
o Import matplotlib and seaborn for plotting.
Step 3: Load Data
1. Load the dataset:
o Use pandas to read data from a file (e.g., CSV).
Step 4: Create Histograms
1. Select columns for histograms:
o Choose numeric columns to visualize the distribution.
2. Plot histograms:
o Use matplotlib or seaborn to create histograms for the selected columns.
o Customize plots (e.g., titles, labels).
Step 5: Create Scatter Plots
1. Select columns for scatter plots:
o Choose pairs of numeric columns to visualize relationships.
2. Plot scatter plots:
o Use matplotlib or seaborn to create scatter plots for the selected pairs.
JHANVEE VERMA
29
MUSKAN RAJPUT 10323210071
o Customize plots (e.g., titles, labels).
Step 6: Display Results
1. Show plots:
o Use matplotlib to display histograms and scatter plots.
o Ensure plots are clear and informative.
CODE:
import numpy as np import
[Link] as plt # Set a
random seed for reproducibility
[Link](123) # Generate
synthetic data n_samples = 300 #
Number of samples
# Generate random heights (in cm) with a normal distribution
heights = [Link](loc=170, scale=10, size=n_samples) # Mean height = 170 cm,
SD = 10 cm
# Generate random weights (in kg) based on heights with some noise
weights = heights * 0.5 + [Link](loc=0, scale=5, size=n_samples) + 50 #
Linear relationship with noise # Create a histogram for heights [Link](figsize=(10, 6))
[Link](heights, bins=20, color='lightgreen', edgecolor='black', alpha=0.7)
[Link]('Histogram of Heights') [Link]('Height (cm)') [Link]('Frequency')
[Link](axis='y', alpha=0.75) [Link]()
# Create a scatter plot of heights vs weights
[Link](figsize=(10, 6)) [Link](heights,
weights, color='purple', alpha=0.7) [Link]('Scatter
Plot of Heights vs Weights') [Link]('Height (cm)')
JHANVEE VERMA
[Link]('Weight (kg)')
[Link](True)
[Link]()
OUTPUT:
30
MUSKAN RAJPUT 10323210071
31