Reputation: 13
I am trying to generate a stacked bar graph using the Altair package, but I'm having trouble with the x-axis. I expected my graph to look something like this, but instead all of the categories for the X-axis are reported as "undefined", and all events are reported in the same vertical bar. I am a complete beginner with python and Jupyter Notebook, so I apologize if I'm missing something extremely obvious.
Here is the code that I've used to define the define the data frame. I've cut usernames out of the image for privacy, but these are just formatted as #@website. Here's a screenshot of my code for defining the dataframe
I checked the types for each column in the data frame, and it matches the types I found in the Altair example I linked earlier. I also checked that there are 6 unique entries in the variable that I wanted to use to define the categories along my x-axis. Here's a screenshot of my code for checking data frame
Here is the code I used to create the bar graph, which collapses all 6 categories into the same "undefined" category on the graph. By looking at the counts, I can tell that all data is included on the graph and the colors are appropriately represented for both usernames. But Altair does not seem to recognize the X-axis as a collection of objects, and is collapsing them all into the same category. I have tried defining parameters.tab_name as a string, but this did not solve the problem. Here's a screenshot of my code for graphing
I'd really appreciate any ideas on the source of the problem, or how to fix it. I'm very new to Jupyter Notebooks, so I'm sure that I'm missing something really basic in the way I'm defining variables. Thank you for your help!
Upvotes: 1
Views: 513
Reputation: 942
You cannot use a .
in your X encoding field. Change the column name or escape the character. See https://altair-viz.github.io/user_guide/troubleshooting.html?highlight=characters#encodings-with-special-characters .
Upvotes: 1