Black Lives Matter. Please consider donating to Black Girls Code today.
Dash Enterprise delivers an incredible 21x cost savings 💸Download the e-book!

Pie chart confusion with textual data

I’m totally new to plot.ly and without wanting to thwart forum regs may well be about to ask a dumb question.

I’m hoping to use plot.ly to process questionnaire data. For example, do you prefer A or B? Imagine this is question 1.

The field heading is the question reference. The values are “A” or “B”. So if 10 people responded the column would look like this:

question_1
A
A
A
A
A
A
B
B
B
B

A 60:40 split in favour of A.

However, when I try and plot a pie chart nothing shows. So I figured perhaps plot.ly requires numeric values. I added a second column “values” and all entries were 1. Setting this as the Values and “question_1” as the labels was a little better. A pie chart showed. But it showed 50:50.

I then updated the “values” to have one of the A records show 6 and one of the B records show 4. All other values in “Values” were set to zero.

This works.

But is there a way to get plot.ly to do this under the hood? Rather than having to re structure all my data?