Skip to content
Advertisement

Why does Python Plotly function with barmode produce an error?

I have been trying to figure this out for a while, so any help would be appreciated.

I am able to run fig_test_reg just fine, but then when I try to run the same parameters through a function I get a ValueError: ValueError: Value of 'pattern_shape' is not the name of a column in 'data_frame'. Expected one of ['Fruit', 'Amount', 'City'] but received: group

code:

JavaScript

why is this happening? how can I run this through a function? what am i missing?

Advertisement

Answer

The issue here is in how you are passing function arguments. If you look at the documentation for the .bar() method, you can see the order of keyword arguments:

JavaScript

Inside your function, you are passing parameters as positional arguments, rather than keyword arguments: bar_chart = px.bar(data,x,y,color,barmode). So, your group value that you are trying to pass to the barmode= parameter actually gets passed to the pattern_shape= parameter, as it is located in that fifth position in the function’s signature.

So, to resolve the problem, you can just convert the positional arguments to keyword arguments in your call to the px.bar() function:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement