Why do I keep getting this error when try to make the bar chart?
TypeError: unsupported operand type(s) for -: ‘str’ and ‘float’
If you do a .info()
on avg_order
, you will see that month is a string and price is a float. You can’t add a string and float.
avg_order.info()
>><class 'pandas.core.frame.DataFrame'>
RangeIndex: 6 entries, 0 to 5
Data columns (total 2 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 month 6 non-null object
1 price 6 non-null float64
dtypes: float64(1), object(1)
memory usage: 224.0+ bytes
So, you have to use range(len())
w/ avg_order to loop through the list.
Like:
Summary
plt.bar(range(len(avg_order)), avg_order.price, yerr=std_order.price, capsize=5)
Your bar chart is also missing the xticks and labels for both axes.
Thank you for helping me out with this! Some days I feel like I am doing well with learning this stuff, then I’ll get stumped on something simple and just can not figure it out. Thank you again!
1 Like