Merge files based on ID, then do calculation
Jump to navigation
Jump to search
import pandas as pd import plotly.express as px ## pip install plotly excel_book1a = 'Purchases - Home A.xlsx' excel_prices = 'PriceBook.xlsx' df_prices = pd.read_excel(excel_prices) df_homea = pd.read_excel(excel_book1a) #print(df_prices, df_homea) ## merge the spreadsheet on the id df_total = df_homea.merge(df_prices, on='ID') ## Create a new column df_total['Total Price'] = df_total['PURCHASED AMOUNT'] * df_total['Price'] df_total.to_excel('totl_combined.xlsx') print(df_total) fig = px.pie(df_total[['MATERIAL', 'Total Price']], values='Total Price', names='MATERIAL') fig.show()