Untitled

mail@pastecode.io avatar
unknown
plain_text
8 months ago
2.1 kB
1
Indexable
Never
# Фильтруем данные по каждому кластеру
df_dil_MO = df[df['label'] == 'dil_MO']
df_dil_KP = df[df['label'] == 'dil_KP']
df_dil_MO_KP = df[df['label'] == 'dil_MO+KP']

# Группируем данные по дате транзакции и суммируем объемы для каждого кластера
grouped_dil_MO = df_dil_MO.groupby('transaction_date').agg({
    'total_monthly_litres_dil': 'sum',
    'MO_dealer_monthly_ton_GZPN': 'sum'
})

grouped_dil_KP = df_dil_KP.groupby('transaction_date').agg({
    'total_monthly_litres_dil': 'sum',
    'KP_dealer_monthly_ton_GZPN': 'sum'
})

grouped_dil_MO_KP = df_dil_MO_KP.groupby('transaction_date').agg({
    'total_monthly_litres_dil': 'sum',
    'MO_KP_dealer_monthly_ton_GZPN': 'sum'
})

# Строим линейные графики
fig, axs = plt.subplots(3, 1, figsize=(15, 18))

# dil_MO Cluster
axs[0].plot(grouped_dil_MO.index, grouped_dil_MO['total_monthly_litres_dil'], label='Total Monthly Litres')
axs[0].plot(grouped_dil_MO.index, grouped_dil_MO['MO_dealer_monthly_ton_GZPN'], label='MO Dealer Monthly Ton GZPN')
axs[0].set_title('dil_MO Cluster Volumes Over Time')
axs[0].set_xlabel('Transaction Date')
axs[0].set_ylabel('Volume')
axs[0].legend()

# dil_KP Cluster
axs[1].plot(grouped_dil_KP.index, grouped_dil_KP['total_monthly_litres_dil'], label='Total Monthly Litres')
axs[1].plot(grouped_dil_KP.index, grouped_dil_KP['KP_dealer_monthly_ton_GZPN'], label='KP Dealer Monthly Ton GZPN')
axs[1].set_title('dil_KP Cluster Volumes Over Time')
axs[1].set_xlabel('Transaction Date')
axs[1].set_ylabel('Volume')
axs[1].legend()

# dil_MO+KP Cluster
axs[2].plot(grouped_dil_MO_KP.index, grouped_dil_MO_KP['total_monthly_litres_dil'], label='Total Monthly Litres')
axs[2].plot(grouped_dil_MO_KP.index, grouped_dil_MO_KP['MO_KP_dealer_monthly_ton_GZPN'], label='MO_KP Dealer Monthly Ton GZPN')
axs[2].set_title('dil_MO+KP Cluster Volumes Over Time')
axs[2].set_xlabel('Transaction Date')
axs[2].set_ylabel('Volume')
axs[2].legend()

plt.tight_layout()
plt.show()
Leave a Comment