[Python] Plot correlation matrix using heatmap

Discussão em 'Python' iniciado por Stack, Fevereiro 28, 2025.

  1. Stack

    Stack Membro Participativo

    I have the following DataFrame (sample image). [​IMG]

    I estimated the correlation matrix between Sales, Income, and Com for each county with the intend on plotting it into a heatmap.

    import numpy as np
    import pandas as pd
    import matplotlib.pyplot as plt
    import seaborn as sns

    r_county = df_staging.groupby('County')[['Sales','Income','Com']].corr()
    plt.figure(figsize=(10,10))
    sns.heatmap(r_county, annot=True)


    However, it plots the entire r_county with A1, A2, A3, and A4 included. Instead I want to plot the heatmap for each county in four subplots.

    How do I go about doing this? Also, how do I extract the correlation matrix for A1 only?

    Thank you very much.

    Continue reading...

Compartilhe esta Página