Shape mismatch: objects cannot be broadcast to a single shape

In the guided project: Star Wars Survey
When I want to plot the mean() i get an error if I use the code below:
error: shape mismatch: objects cannot be broadcast to a single shape
plt.bar(range(6), males[males.columns[9:15]].mean())
plt.show()
plt.bar(range(6), females[females.columns[9:15]].mean())
plt.show()

But when i used the code below it does plot:
plt.bar(range(6),males.iloc[:,9:15].mean())
plt.title(‘Males Mean Ranking’)
plt.show()
plt.bar(range(6), females.iloc[:,9:15].mean())
plt.title(‘Females Mean Ranking’)
plt.show()

But I don’t get the same error for the sum() method, the code below does plot:
plt.bar([range(6),males[males.columns[3:9]].sum())
plt.title(‘Males Seen Sum’)
plt.show()
plt.bar(range(6),females[females.columns[3:9]].sum())
plt.title(‘Females Seen Sum’)
plt.show()

So what is the difference between using: dataframe[dataframe.columns] vs
dataframe.iloc[:] when using plt.plot?

Very strange, mean and sum should not make a difference to the dimensions of the output data structure, only values. If your 3rd code block can plot, i don’t see why the 1st code block cannot, since both are using dataframe[dataframe.columns].

That shape mismatch error occurs when you call plt.bar with too little/many x values compared to height values. Could you check on this?
matplotlib.pyplot.bar(x, height, width=0.8, bottom=None, *, align='center', data=None, **kwargs)

You can make your question more readable by wrapping single line code with single backticks ` and code blocks with triple backticks ``` (opening and closing both on their own lines)

single backtick

Triple backtick line 1
Triple backtick line 2