我怎样才能实现这一目标DoT Product?我无法将一个附加Pandas DataFrame到另一个。我不需要冗长的解决方案,而是需要一个简单的Pandas代码Numpy。
产品价格:
Apple Price = 3
Cherry Price = 4
Blueberry Price = 2
预期输出:
Apple Cherry Blueberry
Mon 13 8 6
Tues 9 7 4
Wed 7 4 0
Thurs 15 6 3
Total Rev.($) 83 63 37
我的代码:
prod_prices = np.array([3,4,2])
prod_prices
prod_days = np.array([[13,9,7,15],
[8,7,4,6],
[6,4,0,3]]).T
prod_days
df_week_sales = pd.DataFrame(prod_days,
index=["Mon","Tues","Wed","Thurs"],
columns=["Apple","Cherry","Blueberry"])
df_week_sales
weekly_total = df_week_sales.dot(prod_prices)
weekly_total
type(weekly_total)
weekly_total_nparray = np.array(weekly_total)
type(weekly_total_nparray)
weekly_total_nparray
df_weekly_total_nparray = pd.DataFrame(weekly_total_nparray.reshape(1,4))
df_weekly_total_nparray
weekly_revenue_data = df_week_sales.append(df_weekly_total_nparray)
weekly_revenue_data
这给了我以下输出:
料青山看我应如是
素胚勾勒不出你
翻阅古今
相关分类