You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to create a bar-chart with the plotly backend. I use the aggregate-function to count the number of items in each category. Let me show an example.
First I create some test-data:
import holoviews as hv
hv.extension('plotly')
import numpy as np
import pandas as pd
samples = 100
pets = ['Cat', 'Dog', 'Hamster', 'Rabbit']
genders = ['Female', 'Male']
pets_sample = np.random.choice(pets, samples)
gender_sample = np.random.choice(genders, samples)
df=pd.DataFrame(data={'pet':pets_sample,'gender':gender_sample,})
df['pet']=pd.Categorical(df['pet'])
df['gender']=pd.Categorical(df['gender'])
# Delete male hamsters so we have an empty category-combination
df=df[~((df['pet']=='Hamster') & (df['gender']=='Male'))]
df['name']=['Animal #'+str(i) for i in range(len(df))]
df=df[['name','pet','gender']]
df
You can solve this problem by adding a new column to the dataframe, just consisting of ones and use np.sum instead of np.count_nonzero and then everything works:
Given that you get an exception, I'll classify this as a bug. Note that the plotly backend is marked as experimental: as Jim says, a PR would be very welcome but otherwise this is unlikely to have high priority.
Holoviews: 1.14.6
Plotly: 5.3.1
Bokeh: 2.3.3
I want to create a bar-chart with the plotly backend. I use the
aggregate
-function to count the number of items in each category. Let me show an example.First I create some test-data:
When I try to plot this, using
I get the following error:
ValueError: Out of range float values are not JSON compliant
.The reason for that is (I think) that there is one NA in the aggregated table:
returns
You can solve this problem by adding a new column to the dataframe, just consisting of ones and use
np.sum
instead ofnp.count_nonzero
and then everything works:I think NA's should default to zero when making Bar-charts. My original approach works fine if I use
bokeh
as backend.The text was updated successfully, but these errors were encountered: