2

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.

ASDu
  • 89
  • 1
  • 5
  • 1
    Try removing `compute()`, why do you think it was needed in the first place? – Omer Tuchfeld Oct 21 '19 at 14:39
  • 1
    Hey! echoing @Omer above - also this post might be helpful https://stackoverflow.com/questions/12286607/making-heatmap-from-pandas-dataframe – the_good_pony Oct 21 '19 at 14:43
  • Thank you for the answer. Unfortunatly if i remove the "compute()" I will get the error: ValueError: cannot reshape array of size 0 into shape (1,3) @the_good_pony: I need to use the hvplot lib. since I use panel in the rest of my code and this only works with hvplot. I should have made that clear. – ASDu Oct 21 '19 at 15:00
  • 1
    @ASDu oh right, so you're trying to do something like this https://hvplot.pyviz.org/user_guide/Plotting.html (this looks like a fascinating package btw) – the_good_pony Oct 21 '19 at 15:03
  • Yes exactly. This is were my code came from. – ASDu Oct 21 '19 at 15:13

1 Answers1

4

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

the_good_pony
  • 490
  • 5
  • 12