[enter image description here][1]I get the following error:
KeyError: "Passing list-likes to .loc or [] with any missing labels is no longer supported. The following labels were missing: Index(['Japan', 'Italy', 'Spain', 'Norway', 'Mexico'], dtype='object', name='Country'). See https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike
I have searched for days and am at a complete loss to what it means and how to mitigate it. I can post my code, if that would help in deciphering it?
Any help or insight would be greatly appreciated (I'm at beginners level, writing Python, so please bear with me if the solution has been there all along).
# We have 11 clusters which we can put on a 3x4 grid of plots, and disable the last plot
fig, ax = plt.subplots(int(len(clusters)/4)+1,4,figsize=(13,10))
ax = ax.ravel() # This makes iterating over axes simpler
for i, (cluster, axes) in enumerate(zip(clusters, ax)): # One plot per centroid
# Pull out cluster genre data
indices = subset[db_clust == cluster].index
cluster_data = data.loc[indices]
# Pull out counts per country, greatest first, also get number of active bands per country
count = cluster_data.groupby('Country')['GenreTerms'].count().sort_values(ascending=False)
count_active = cluster_data[cluster_data['Status'] == 'Active'].groupby('Country')['GenreTerms'].count()
# Pull out top 3 most common terms
term_count = count_terms(cluster_data['GenreTerms'])
top_terms = term_count['Term'][:3]
# Define color for cluster
color = colors[cluster]
# Define y-axis coordinates
coords = np.arange(10, 0, -1)
# kwargs for barh
bar_kw = {'height': 0.5, 'color': color, 'align': 'center'}
# Plot bars representing only active bands (note using index of original data)
axes.barh(bottom=coords, width=count_active[count[:10].index], **bar_kw, alpha=0.75, lw=0, label='Active')
# overlay horizontal bars representing all bands
axes.barh(bottom=coords, width=count[:10], **bar_kw, alpha=0.25, label='Non-Active')
if i == 0:
axes.legend(frameon=False, loc=0)
# Set title using 3 most common terms from cluster
axes.set_title('C({}): {}, {}, {}'.format(cluster, *top_terms))
# Format country labels, shorten longer names for more compact layout
axes.set_yticks(coords)
ticklabels = count[:10].index
ticklabels = ticklabels.str.replace('United States', 'US').str.replace('United Kingdom', 'UK')
axes.set_yticklabels(ticklabels, ha='right', va='center')
# Format plot
axes.set_ylim(0.25, 10.75)
axes.grid('off', axis='y')
# Hide last plot
ax[-1].set_axis_off()
fig.tight_layout()
fig.suptitle('# of Bands per top 10 countries in each cluster', y=1.025, fontsize=16, weight='bold')