下面是我的代码,我做的条形图是不对的。对于饼图,我不断得到这个错误:(ValueError:cannot copy sequence with size 9994 to array axis with dimension 2)
The bars instead of showing the number of profit, it somehow make it the month
def totalProfit_month():
#total profit by month
ProfitDataMonth = OrdersOnlyData
ProfitDataMonth["Profit"] = ProfitDataMonth["Profit"].sum()
ProfitDataMonth["Month"] = ProfitDataMonth["Order Date"].dt.month
MonthlyProfit = ProfitDataMonth[["Month", "Profit"]]
MonthlyProfitSum = MonthlyProfit.groupby(by="Month").sum()
MonthlyProfitSum['Profit'] = MonthlyProfitSum['Profit'].map("{:.2f}".format)
MonthlyProfitSum['Profit'] = pd.np.where(MonthlyProfitSum['Profit'].astype(float)
< 0, '-$' + MonthlyProfitSum['Profit'].astype(str).str[1:],
'$' + MonthlyProfitSum['Profit'].astype(str))
print(MonthlyProfitSum)
MonthlyProfitSum = MonthlyProfitSum.reset_index()
#barchart
# barchart_mostProfitable_month = sns.barplot(x="Month", y="Profit", data=MonthlyProfitSum)
# barchart_mostProfitable_month.set_title("Sales by Profit")
#piechart
labels = ProfitDataMonth
sizes = [ProfitDataMonth[["Month", "Profit"]]]
fig1, ax1 = plt.subplots()
ax1.pie(sizes, labels=labels,
shadow=True, startangle=90)
ax1.axis('equal')
plt.show()[enter image description here][1]
最近我在大学里遇到了Matplotlib及其应用程序,我做了很多基于它的程序。我将尝试通过基本知识来解决您的问题,我希望评论中的相关讨论将指导您:)。你知道吗
对于饼图
对于条形图
我希望这个答案是有帮助的。你知道吗
相关问题 更多 >
编程相关推荐