Skip to content
New Workbook
Sign up
Competition - motorcycle parts (copy)

Importing modules


import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
plt.style.use('ggplot')
#plt.style.use('seaborn-white')

Reading in the sales data

 
# Reading in the sales data
sales = pd.read_csv('data/sales_data.csv', parse_dates=['date'])

# Take a look at the first datapoints
sales.head()
sales.info()
sales.describe()
sales.head()

Checking for null values

sales.isnull().sum()

Extracting Day and Month name from date

sales["Week_day"]=sales["date"].dt.day_name()
sales["Month"]=sales["date"].dt.month_name()
sales.info()

Defining function for plotting Bar Plot

def plot_barPlot(data,x,y,title,xlabel,ylabel):
    '''Plots bar plot'''
    plt.figure(figsize=(12,8))
    splot=sns.barplot(data=data,x=x,y=y,ci=0)

    for p in splot.patches:
        splot.annotate(round(p.get_height(),2),#text that you want to write on top
                       (p.get_x() + p.get_width() / 2., p.get_height()),# coordinates where text should be there
                       ha = 'center', va = 'center',# alignment of the text
                       xytext = (0, 10),# distance of text from top of the patch
                       textcoords = 'offset points') #do not change and remove it
    plt.title(title)
    plt.xlabel(xlabel)
    plt.ylabel(ylabel)
    plt.show()