Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
957 B
1
Indexable
Never
grouped_df = df.groupby(['transaction_date', 'label']).agg({
    'MO_dealer_monthly_ton_GZPN': 'mean',
    'KP_dealer_monthly_ton_GZPN': 'mean',
    'total_monthly_ton_dil' : 'mean',
    'client_inn_dil': 'count'
}).reset_index()

fig, ax1 = plt.subplots(figsize=(12, 6))

colors = {'dil_MO': 'blue', 'dil_KP': 'green', 'dil_MO+KP': 'red', 'Прочие': 'gray'}
grouped_df['color'] = grouped_df['label'].apply(lambda x: colors[x])

for label, group in grouped_df.groupby('label'):
    ax1.scatter(group['transaction_date'], group['total_monthly_ton_dil'], label=label, color=colors[label], s=50)

ax1.set_xlabel('Дата транзакции')
ax1.set_ylabel('Количество тонн всего', color='tab:blue')
ax1.tick_params(axis='y', labelcolor='tab:blue')
ax1.legend(title='Cluster')

plt.title('Количество тонн (мес.) по кластерам')
plt.xticks(rotation=45)
plt.tight_layout()
plt.show()
Leave a Comment