I am quite new to coding, and this seems to be some fundamental aspect of Python/Pandas/Matplotlib that I am not understanding. I am happy with general answers, but, for reference, here is my specific context:
top_100.index = top_100.Company
top_100 = top_100.dropna()
top_20 = top_100[(top_100.Rank > 10) & (top_100.Rank < 21)]
top_20 = top_20.sort_values('Rank', ascending = True)
top_20.index = top_20.Rank
plt.figure()
top_20.plot.pie(y = ['USA_Retail_Sales_million',\
'Worldwide_Retail_Sales_million'], subplots = True,\
figsize = (16, 8), autopct = '%1.1f%%', legend = False)
plt.show()
The full error message reads:
runcell(65, 'C:/Users/Adam/Desktop/DSCI 200/Practice/Wk 3 Practice.py')
Traceback (most recent call last):
File "C:\Users\Adam\Desktop\DSCI 200\Practice\Wk 3 Practice.py", line 359, in <module>
top_20.plot.pie(y = ['USA_Retail_Sales_million',\
File "C:\Users\Adam\anaconda3\lib\site-packages\pandas\plotting\_core.py", line 1528, in pie
return self(kind="pie", **kwargs)
File "C:\Users\Adam\anaconda3\lib\site-packages\pandas\plotting\_core.py", line 908, in __call__
data.index.name = y
File "C:\Users\Adam\anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 1190, in name
maybe_extract_name(value, None, type(self))
File "C:\Users\Adam\anaconda3\lib\site-packages\pandas\core\indexes\base.py", line 5665, in maybe_extract_name
raise TypeError(f"{cls.__name__}.name must be a hashable type")
TypeError: Int64Index.name must be a hashable type
<Figure size 432x288 with 0 Axes>
For what it's worth, I don't have anywhere near 5600 lines of code.
Every time I run this code, I get the TypeError: Int64Index.name must be a hashable type
. I have changed the index multiple time, but have come to realize that I don't think it's my index that is the issue; I am obviously asking it to change an immutable 'something'. I just don't know what that 'something' is, or how to otherwise approach the issue. Perhaps (obviously) I have a very nascent understanding of what Int64Index.name
is and what I am asking it to do. I have certainly not ruled that my code is just plain wrong, but is seems correct to me - for what little that's worth.