1

I saw a sample from the internet to build a simple pie chart from Matplotlib but not sure how to embed it with my dataset (https://gist.github.com/datomnurdin/33961755b306bc67e4121052ae87cfbc).

from pandas import DataFrame
import matplotlib.pyplot as plt
import pandas as pd

df = pd.read_csv('data.csv')

my_labels = 'Positive','Neutral','Negative'
my_colors = ['lightblue','lightsteelblue','silver']
plt.pie(df, labels=my_labels, autopct='%1.1f%%', startangle=15, shadow = True, colors=my_colors)
plt.title('Sentiment Overview')
plt.axis('equal')
plt.show()

P.S: The dataset didn't contain any labels, only values.

1 Answer 1

2

I would do something like this:

my_labels = {1:'Positive',0:'Neutral',-1:'Negative'}
my_colors = ['lightblue','lightsteelblue','silver']

# count the values to plot pie chart
s = df.sentiment.map(my_labels).value_counts()

plt.pie(s, labels=s.index, autopct='%1.1f%%', colors=my_colors)
# also
# s.plot.pie(autopct='%1.1f%%', colors=my_colors)

plt.show()

Output:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.