0% found this document useful (0 votes)
3 views1 page

Data Analysis with Pandas and Visualization

The document outlines a Python script that generates a synthetic dataset with numerical and categorical columns, performs numerical analysis, and visualizes the data using histograms, boxplots, bar charts, and pie charts. It includes calculations for mean, median, mode, standard deviation, variance, and outlier detection using the IQR method. Additionally, it provides frequency counts for the categorical data and visual representations of these counts.

Uploaded by

iamnotnoob8888
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Data Analysis with Pandas and Visualization

The document outlines a Python script that generates a synthetic dataset with numerical and categorical columns, performs numerical analysis, and visualizes the data using histograms, boxplots, bar charts, and pie charts. It includes calculations for mean, median, mode, standard deviation, variance, and outlier detection using the IQR method. Additionally, it provides frequency counts for the categorical data and visual representations of these counts.

Uploaded by

iamnotnoob8888
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import pandas as pd

import numpy as np
import [Link] as plt
import seaborn as sns
import warnings
[Link]('ignore')

# Generate synthetic dataset


[Link](42)
data = {
'numerical_column': [Link]([Link](20, 80, 95), [150, 160, 170, 5,
10]),
'categorical_column': [Link](['A', 'B', 'C', 'D'], 100)
}
df = [Link](data)
df.to_csv('Sample_Data.csv', index=False) # Optional: Save to CSV
df = pd.read_csv('Sample_Data.csv') # Load the dataset

# Numerical analysis
num = df['numerical_column'].dropna()
print("Dataset Preview:\n", [Link]())
print(f"\n--- Numerical Stats for 'numerical_column' ---")
print(f"Mean: {[Link]():.2f} | Median: {[Link]()} | Mode:
{[Link]().values}")
print(f"Std Dev: {[Link]():.2f} | Variance: {[Link]():.2f} | Range: {[Link]() -
[Link]()}")

# Plot histogram & boxplot


[Link](figsize=(10, 4))
[Link](num, bins=20, kde=True).set(title='Histogram')
[Link]()
[Link](x=num).set(title='Boxplot')
[Link]()

# Outlier detection using IQR


Q1, Q3 = [Link]([0.25, 0.75])
IQR = Q3 - Q1
outliers = num[(num < Q1 - 1.5 * IQR) | (num > Q3 + 1.5 * IQR)]
print(f"\nOutliers Detected:\n{[Link]}")

# Categorical analysis
cat_counts = df['categorical_column'].value_counts()
print(f"\n--- Category Frequencies ---\n{cat_counts}")

# Bar & pie chart


[Link](figsize=(10, 4))
cat_counts.plot(kind='bar', color='lightgreen', title='Bar Chart')
[Link]('Category')
[Link]('Count')
plt.tight_layout()
[Link]()
cat_counts.plot(kind='pie', autopct='%1.1f%%', title='Pie Chart')
[Link]('')
plt.tight_layout()
[Link]()

You might also like