Fake dataframe creation:
df = pd.DataFrame()
df['Datetime'] = pd.date_range(start = '01/07/2018', end = '13/08/2021', freq = '15min')
df['Quantity'] = np.random.rand(len(df))
Starting from this point, you should extract month and year and save them in separate columns:
df['month'] = df['Datetime'].dt.month
df['year'] = df['Datetime'].dt.year
Then you have to compute the sum of 'Quantity' by month for each year:
df = df.groupby(by = ['month', 'year'])['Quantity'].sum().reset_index()
After this passage, you should have a dataframe like this:
Datetime Quantity month year
0 2018-01-07 00:00:00 0.226113 1 2018
1 2018-01-07 00:15:00 0.222872 1 2018
2 2018-01-07 00:30:00 0.835484 1 2018
3 2018-01-07 00:45:00 0.775771 1 2018
4 2018-01-07 01:00:00 0.972559 1 2018
5 2018-01-07 01:15:00 0.418036 1 2018
6 2018-01-07 01:30:00 0.902843 1 2018
7 2018-01-07 01:45:00 0.012441 1 2018
8 2018-01-07 02:00:00 0.883437 1 2018
9 2018-01-07 02:15:00 0.183561 1 2018
Now the dataframe is ready to be plotted; using seaborn:
fig, ax = plt.subplots()
sns.barplot(ax = ax, data = df, x = 'month', y = 'Quantity', hue = 'year')
plt.show()
Complete Code
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.DataFrame()
df['Datetime'] = pd.date_range(start = '01/07/2018', end = '13/08/2021', freq = '15min')
df['Quantity'] = np.random.rand(len(df))
df['month'] = df['Datetime'].dt.month
df['year'] = df['Datetime'].dt.year
df = df.groupby(by = ['month', 'year'])['Quantity'].sum().reset_index()
fig, ax = plt.subplots()
sns.barplot(ax = ax, data = df, x = 'month', y = 'Quantity', hue = 'year')
plt.show()
