I am attempting to construct a pie chart of the weighting of certain sectors in a index.
given this sample data frame.
Data = { 'Company': ['Google', 'Nike', 'Goldman', 'Tesla'], 'Ticker': ['GOOG', 'NKE', 'GGG', 'TSA'], 'Sector': ['Tech', 'Consumer', 'Financial', 'Auto'], 'Weighting': ['10', '20', '40', '30']
df = pd.DataFrame(Data)
I have tried to create a dictionary of weights by sector.
Weight_Sector = df.groupby('Sector')['Weighting'].apply(list).to_dict()
I checked the dictionary and all was good. However when I went on to plot the pie chart with the following code, I get an error 'ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 1 dimensions. The detected shape was (9,) + inhomogeneous part.
plt.pie(Weight_Sector.values(), startangle=90, autopct='%.1f%%')
In my actual data frame and dictionary there is a lot more values and most dictionary sectors have more than 1 item as a weight in them corresponding to different companies.
Any help is appreciated!!
