Skip to content

Instantly share code, notes, and snippets.

@Priyanku-AI
Priyanku-AI / Pandas GroupBy Code
Created December 13, 2023 08:44
Pandas GroupBy Function
import pandas as pd
# Making a score list
data = {'Subject': ['Math', 'English', 'Math', 'English', 'Math'],
'Score': [85, 90, 92, 88, 78]}
df = pd.DataFrame(data)
# Grouping by 'Subject' and finding the average score
grouped_data = df.groupby('Subject').mean()
@Priyanku-AI
Priyanku-AI / Box plot code
Created December 6, 2023 17:46
How to create a Box plot?
import seaborn as sns
import matplotlib.pyplot as plt
# Example Data (randomly generated)
data = sns.load_dataset("tips")
# Creating the Box Plot
sns.boxplot(x="day", y="total_bill", data=data, palette="Set2")
# Create a box plot of total bill amounts grouped by day, using the 'Set2' color palette
@Priyanku-AI
Priyanku-AI / Heatmap code
Created December 2, 2023 19:02
How to create a heatmap?
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
# Generating a synthetic correlation matrix
np.random.seed(42)
data = np.random.rand(10, 10)
# Creating the Heatmap
sns.heatmap(data, cmap="YlGnBu", annot=True, fmt=".2f", linewidths=.5)
@Priyanku-AI
Priyanku-AI / Histogram Code
Created December 1, 2023 19:33
How to create a histogram?
import matplotlib.pyplot as plt
import numpy as np
# Example Data (randomly generated)
data = np.random.randn(1000) * 30 + 50 # Creating a sample dataset with a normal distribution
# Creating the Histogram
plt.hist(data, bins=30, color='skyblue', edgecolor='black')
# Create a histogram with 30 bins, using skyblue color and black edges
@Priyanku-AI
Priyanku-AI / Pie Chart Code
Created November 30, 2023 20:24
How to create a Pie chart?
import matplotlib.pyplot as plt
# Example Data
categories = ['Category A', 'Category B', 'Category C', 'Category D']
values = [25, 30, 20, 25]
# Creating the Pie Chart
plt.pie(values, labels=categories, autopct='%1.1f%%', startangle=90, colors=['#ff9999','#66b3ff','#99ff99','#ffcc99'])
# Create a pie chart with the given values and categories
# autopct displays the percentage on each slice, startangle rotates the chart, and colors customize each slice
@Priyanku-AI
Priyanku-AI / Scatter Plot Code
Created November 30, 2023 17:20
How to create a Scatter Plot?
import matplotlib.pyplot as plt
# Example Data
study_hours = [3, 5, 7, 2, 6, 8, 4, 5, 7, 1]
exam_scores = [60, 75, 85, 50, 70, 90, 65, 80, 88, 45]
# Creating the Scatter Plot
plt.scatter(study_hours, exam_scores, color='blue', marker='o', label='Students')
# Scatter the points on the graph with study hours on the x-axis and exam scores on the y-axis
# Customize the appearance with a blue color, circular markers, and label the data as 'Students'
@Priyanku-AI
Priyanku-AI / Line Chart Code
Created November 28, 2023 10:01
How to create line charts?
import matplotlib.pyplot as plt
# Example Data
time = [1, 2, 3, 4, 5] # X-axis values (e.g., time)
values = [10, 12, 8, 15, 11] # Y-axis values (e.g., some measurement)
# Creating the Line Chart
plt.plot(time, values, marker='o', linestyle='-') # 'o' for markers, '-' for line style
# Adding Labels
@Priyanku-AI
Priyanku-AI / Bar Chart Code
Created November 19, 2023 17:43
How to create Bar Charts?
import matplotlib.pyplot as plt
# Example data
categories = ['Category A', 'Category B', 'Category C']
values = [25, 40, 30]
# Bar chart
plt.bar(categories, values, color=['skyblue', 'salmon', 'lightgreen'])
plt.title('Bar Chart for Categorical Data')
plt.xlabel('Categories')
@Priyanku-AI
Priyanku-AI / Predicting Superhero Strength using LR
Created November 11, 2023 10:09
Simple Implementation of Linear Regression where we are predicting superheroes' strength based on the hours they invest in honing their skills.
# Import necessary libraries
import numpy as np
import pandas as pd
from sklearn.linear_model import LinearRegression
# Set a seed for reproducibility
np.random.seed(42)
# Simulate data for superheroes
superheroes_data = {
@Priyanku-AI
Priyanku-AI / Pandas Profiling Example
Created November 10, 2023 18:45
Applying Pandas Profiling to a toy dataset
import pandas as pd
from pandas_profiling import ProfileReport
import numpy as np
# Create a toy dataset
data = {
'Name': ['Paul', 'Pallabi', 'Peter', 'Gwen', 'Emily'],
'Age': [24, 23, 35, 22, 28],
'Salary': [50000, 60000, 75000, 45000, 55000],
'Gender': ['Male', 'Female', 'Male', 'Female', 'Female'],