import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv('MoneyWeeks_ForHeatMap.csv')
df.head(10)
Week | Transaction | |
---|---|---|
0 | 1 | 1106.52 |
1 | 1 | -346.17 |
2 | 2 | 1076.56 |
3 | 2 | -338.12 |
4 | 3 | 894.29 |
5 | 3 | -423.59 |
6 | 4 | 1050.88 |
7 | 4 | -208.13 |
8 | 5 | 1014.59 |
9 | 5 | -478.43 |
grouped_df = df.groupby('Week').agg({'Transaction': 'sum'})
result_df = grouped_df.reset_index()
result_df = result_df.rename(columns={'Transaction': 'Total Profit'})
result_df.head()
Week | Total Profit | |
---|---|---|
0 | 1 | 760.35 |
1 | 2 | 738.44 |
2 | 3 | 470.70 |
3 | 4 | 842.75 |
4 | 5 | 536.16 |
df_pivot = result_df.pivot_table(values='Total Profit', index=result_df.index // 4, columns=result_df.index % 4)
plt.figure(figsize=(12, 8))
heatmap = sns.heatmap(df_pivot, cmap='YlGnBu', annot=True, fmt=".2f",linewidths=.5, cbar_kws={'label': 'Profit (£)'})
heatmap.set_yticklabels([f"Period {i}" for i in range(1, 14)], rotation=0)
heatmap.set_xticklabels([f"Week {i}" for i in range(1, 5)], rotation=45)
plt.title('Weekly Profit Heatmap')
plt.show()