Search code examples
pythonpandasheatmaphvplot

Plot Heatmap of dataframe


Given a pandas dataframe, which looks similar to this one:

 d = {'name_1': ['a', 'b', 'c'], 'classifikation' : ['x','x','y'] ,  'value': [1, 2, 3]}
 df = pd.DataFrame(data=d)

I woule like to plot a simple heatmat using hvplot. But runing

df.compute().hvplot.heatmap(x='name_1', y='classifikation ', C='value', reduce_function=np.mean, colorbar=True)

just gives me an error:

AttributeError: 'DataFrame' object has no attribute 'compute'

I cant figure out what I should do to solve this problem. Maybe one of you could help me how I could plot a heatmap for dataframes of this typ.


Solution

  • I tried this

    Import packages

    import numpy as np
    import hvplot.pandas  
    

    Set up dataframe

    d = {'name_1': ['a', 'b', 'c'], 'classification' : ['x','x','y'] ,  'value': [1, 2,3]}
    df = pd.DataFrame(data=d)
    

    produce the heat map

    df.hvplot.heatmap(x='name_1', y='classification', C='value', reduce_function=np.mean, colorbar=True)
    

    I get this

    enter image description here

    So you'll notice I removed .compute(). I believe that only Dask DataFrames use .compute() .

    I looked here for guidance on setting up the heatmap