Understanding Data
Data, What Are You Telling Me?
12 min readMay 8, 2023
Insights are within the sea of data. Data is telling us a story of the past, present and future all the time, but we need to `see` it.
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
# Load example data
tips_df = pd.read_csv("https://raw.githubusercontent.com/mwaskom/seaborn-data/master/tips.csv")
# Read columns into lists
total_bill = tips_df['total_bill'].tolist()
tip = tips_df['tip'].tolist()
sex = tips_df['sex'].tolist()
smoker = tips_df['smoker'].tolist()
day = tips_df['day'].tolist()
time = tips_df['time'].tolist()
size = tips_df['size'].tolist()
bill_ranges = [0, 10, 20, 30, 40, 50, 60, 70, 80]
labels = ['0-10', '10-20', '20-30', '30-40', '40-50', '50-60', '60-70', '70-80']
# Group the tips by bill ranges and sex
tips_df['total_bill_range'] = pd.cut(tips_df['total_bill'], bins=bill_ranges, labels=labels, include_lowest=True)
bill_sex_group = tips_df.groupby(['total_bill_range', 'sex']).size().reset_index(name='count')
# Plot the bar chart using seaborn
sns.barplot(x="total_bill_range", y="count", hue="sex", data=bill_sex_group)
plt.title("Total Tips by Bill Ranges and Sex")
plt.xlabel("Total Bill Ranges")
plt.ylabel("Total Tips")
plt.show()