2

I am concerned with a single column (fruit) from my df:

| fruit               |
| --------------------|  
| apple, orange       | 
| banana              |
| grapefruit, orange  |
| apple, banana, kiwi |

I want to plot the values from fruit to a pie chart to get a visual representation of the distribution of each individual fruit

I run: df.plot(kind='pie', y='fruit')

But this gives a TypeError: '<' not supported between instances of 'str' and 'int'

I have read: How can I read inputs as numbers?

But I can't see how it helps solve my problem

Any help much appreciated!

Tom Bomer
  • 83
  • 7

1 Answers1

3

You can split and explode:

(df['fruit']
 .str.split(',\s*')
 .explode()
 .value_counts()
 .plot(kind='pie')
)

Output:

pie chart

mozway
  • 194,879
  • 13
  • 39
  • 75