Merge files based on ID, then do calculation

From rbachwiki
Revision as of 21:25, 9 September 2020 by Bacchas (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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()



Excel files are in: G:\Dropbox\All Folders\python\python_desktop\automate_excel

Back To Top - Main Category/ Excel Category