In [ ]:
import seaborn as sns
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
In [ ]:
df = pd.read_csv('ad_sales.csv')
df.head()
Out[ ]:
| ID | TV | Radio | Newspaper | Sales | |
|---|---|---|---|---|---|
| 0 | 1 | 230.1 | 37.8 | 69.2 | 22.1 |
| 1 | 2 | 44.5 | 39.3 | 45.1 | 10.4 |
| 2 | 3 | 17.2 | 45.9 | 69.3 | 9.3 |
| 3 | 4 | 151.5 | 41.3 | 58.5 | 18.5 |
| 4 | 5 | 180.8 | 12.8 | 58.4 | 12.9 |
In [ ]:
#1.
plt.figure(figsize=(10,5))
sns.histplot(data= df, x='Sales', color='lightgreen', kde=True,
fill=False, binwidth= 5)
plt.show()
In [ ]:
#majority of the distrribution is around 10 to 15 sales
In [ ]:
2.
plt.figure(figsize=(8,4))
sns.jointplot(data=df, x='TV', y='Radio', kind='reg')
plt.show()
<Figure size 800x400 with 0 Axes>
In [ ]:
#we found that there is no relaitonship between Tv and Radio sales
In [ ]:
#3.
plt.figure(figsize=(8,4))
sns.jointplot(data=df, x='TV', y='Sales', kind='reg')
plt.show()
<Figure size 800x400 with 0 Axes>
In [ ]:
# we found a postive realtionship between TV and Sales
In [ ]:
#4.
plt.figure(figsize=(8,4))
sns.jointplot(data=df, x='Newspaper', y='Sales', kind='reg')
plt.show()
<Figure size 800x400 with 0 Axes>
In [ ]:
#we found a positive relationship between Newspaper and Sales
In [ ]:
# hw 2 &3
In [ ]:
In [ ]:
df2 = pd.read_csv('energy.csv')
df2.head()
Out[ ]:
| Date | commercial | industrial | |
|---|---|---|---|
| 0 | 1/1/01 | 629 | 13128 |
| 1 | 2/1/01 | 548 | 11421 |
| 2 | 3/1/01 | 553 | 12454 |
| 3 | 4/1/01 | 550 | 11674 |
| 4 | 5/1/01 | 575 | 11751 |
In [ ]:
df2.dtypes
Out[ ]:
| 0 | |
|---|---|
| Date | object |
| commercial | int64 |
| industrial | int64 |
In [ ]:
df2['Date']=pd.to_datetime(df2['Date'])
df2.head()
/tmp/ipython-input-321837906.py:1: UserWarning: Could not infer format, so each element will be parsed individually, falling back to `dateutil`. To ensure parsing is consistent and as-expected, please specify a format. df2['Date']=pd.to_datetime(df2['Date'])
Out[ ]:
| Date | commercial | industrial | |
|---|---|---|---|
| 0 | 2001-01-01 | 629 | 13128 |
| 1 | 2001-02-01 | 548 | 11421 |
| 2 | 2001-03-01 | 553 | 12454 |
| 3 | 2001-04-01 | 550 | 11674 |
| 4 | 2001-05-01 | 575 | 11751 |
In [ ]:
#1
plt.figure(figsize=(12,5))
sns.lineplot(data= df2, x='Date',y='commercial', linestyle='--', markersize='8',
marker='o', color='limegreen', mfc='orange', mec='yellow', label='comm')
#sns.lineplot(data=df, x='Date',y='Platinum', linestyle='--', markersize='12',
# marker='x', color='teal', mfc='black', mec='steelblue', label='platinum')
plt.show()
In [ ]:
#this visual shows commercial energy generation over time
In [ ]:
#2
plt.figure(figsize=(12,5))
sns.lineplot(data= df2, x='Date',y='commercial', linestyle='--', markersize='8',
marker='o', color='limegreen', mfc='orange', mec='yellow', label='comm')
sns.lineplot(data=df2, x='Date',y='industrial', linestyle='--', markersize='12',
marker='x', color='teal', mfc='black', mec='steelblue', label='platinum')
plt.show()
In [ ]:
#this visual shows commercial and industrial energy generation over time
In [ ]:
#3
def func_(x):
outcome= x**3 + 2 * x**2 + 12
return outcome
In [ ]:
#4
x = np.linspace(1,10,100)
y = func_(x)
In [ ]:
plt.figure(figsize=(4, 4))
plt.plot(x, y, color='indigo', linestyle='--', linewidth=3)
#plt.title('Cubic Function')
plt.xlabel('x')
plt.ylabel('y')
plt.grid()
plt.show()
In [ ]:
df3 = pd.read_csv('customer.csv')
df3.head()
Out[ ]:
| Education | Income | Kidhome | Marital_Status | Recency | MntFruits | MntMeatProducts | NumStorePurchases | NumWebPurchases | NumWebVisitsMonth | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Graduation | 58138.0 | 0 | Single | 58 | 88 | 546 | 4 | 8 | 7 |
| 1 | Graduation | 46344.0 | 1 | Single | 38 | 1 | 6 | 2 | 1 | 5 |
| 2 | Graduation | 71613.0 | 0 | Together | 26 | 49 | 127 | 10 | 8 | 4 |
| 3 | Graduation | 26646.0 | 1 | Together | 26 | 4 | 20 | 4 | 2 | 6 |
| 4 | PhD | 58293.0 | 1 | Married | 94 | 43 | 118 | 6 | 5 | 5 |
In [ ]:
#1.
sns.countplot(data=df3, x='Education', hue= 'Education')
plt.xticks(rotation=20)
plt.show()
In [ ]:
# most of the customers have a college degree
In [ ]:
#2
sns.catplot(data=df3, y='Income', x='Kidhome', kind= 'box', hue= 'Kidhome')
plt.xticks(rotation=20)
plt.show()
In [ ]:
# we found that if you have less kids, you have a higher income
In [ ]:
#3
plt.figure(figsize=(8,4))
sns.jointplot(data=df3, x='NumStorePurchases', y='NumWebPurchases', kind='reg')
plt.show()
<Figure size 800x400 with 0 Axes>
In [ ]:
# they have a positive relationship
In [ ]:
#4
sns.kdeplot(data=df3, x='Income', hue='Marital_Status', common_norm=False)
plt.show()
In [ ]:
sns.catplot(data=df3, y='Income', x='Marital_Status', kind= 'box', hue= 'Marital_Status')
plt.xticks(rotation=20)
plt.show()
In [ ]:
#people who are single have a higher income, people who are alone tend to have the lowest income
In [ ]:
#5
sns.catplot(data=df3, y='Income', x='Education', kind= 'box', hue= 'Education')
plt.xticks(rotation=20)
plt.show()
In [ ]:
# on average people with Masters and PHDs tend to have the higher incomes compared to other education levels