-1

I am trying to build a pie chart using the different variable values that I created. However, I am not able to build an chart.

It displays the following error: x must be 1D

I'm new to Python and would appreciate any information. Thank you in advance.enter image description here

  • 1
    Please post your code as text, not image – Lesiak Nov 19 '21 at 21:39
  • Something (probably all elements) in `sizes` is/are not of type float. That is, your list is multidimensional. `sizes` should like akin to say `[0.1, 0.2, 0.3, 0.4]`. Print it out to your console, see what it is you want to keep and then redefine this variable and you should be good. – havingaball Nov 19 '21 at 21:44
  • and yes, in future please don't include your code as an image. Instead, format your question text. – havingaball Nov 19 '21 at 21:45

1 Answers1

0

You use value_counts() function in the wrong way:

import pandas as pd
index = pd.Index(['c#', 'java', 'c#', 'c#', 'java'])
index.value_counts()
# Output:
# c#      3
# java    2
# dtype: int64

index.value_counts('c#') # This is wrong and misleading
# Output:
# c#      0.6
# java    0.4
# dtype: float64

index.value_counts()['c#']
# Output:
3

Check the value_counts documentation to understand this behaviour:

Index.value_counts(normalize=False, sort=True, ascending=False, bins=None, dropna=True)[source]

The first positional argument is interpreted as a boolean, and specifies whether to normalize the output.

Lesiak
  • 22,088
  • 2
  • 41
  • 65