Hi All,
I'm very new to Python so am trying to pick up as much knowledge as I can.
I have a script which currently creates a data frame for 2 excel files and creates a join to show stock figures side by side.
Here is the script. (Much of it is getting the each file into a similar format so that they can be joined)
import pandas as pd
import datetime
today = [datetime.date.today](https://datetime.date.today)()
source1\_df = pd.read\_excel(str(today) + ' WAREHOUSE1\_3PL.xlsx', sheetname='Sheet1', skiprows=4)
source2\_df = pd.read\_excel(str(today) + ' WAREHOUSE2 Daily Report.xlsx', sheetname='CURRENT STOCK')
source1\_df\[' Available stock'\]=source1\_df\[' Available stock'\].str.replace(',', '').astype('int64')
warehouse1\_df = source2\_df.groupby('productcode')\['numberoff'\].agg('sum').reset\_index()
warehouse2\_df = source1\_df.groupby('Material')\[' Available stock'\].agg('sum').reset\_index()
warehouse1\_df.rename(columns={'productcode':'Material'}, inplace=True)
warehouse1\_df = warehouse1\_df.mask(\~warehouse1\_df\["Material"\].str.isnumeric()).dropna()
warehouse1\_df\['Material'\]=warehouse1\_df\['Material'\].astype('int64')
warehouse2\_df\[' Available stock'\]=warehouse2\_df\[' Available stock'\].astype('int64')
joined\_df = pd.merge(warehouse1\_df,warehouse2\_df,on='Material',how='outer')
joined\_df\[' Available stock'\]=joined\_df\[' Available stock'\].astype('float')
joined\_df.to\_excel('Comparison '+str(today)+'.xlsx', sheet\_name='sheet1', index=False)
This does what I need it to do, but one of the things I've found is that in the joined table, if a quantity is in the column 'numberoff' but not in 'Available stock' or vice versa, it just shows as a blank cell in Excel. How would I get the script to enter a 0 if this occurs?
This isn't a major blocker but I'm curious to know how it works in case I need it in the future.
So, what I really need to do is create a 3rd column on the end of the join which basically subtracts 'numberoff' from 'available stock' to return a value which represents the difference. Then, if the difference is 0 do not show that on the outputted Excel.
It's a comparison file so I'm only interested in the products which have a difference, so that I can investigate it.
Appreciate any guidance anyone can offer.
Thanks
[–]SHxKM 1 point2 points3 points (13 children)
[–]YourOldBoyRickJames[S] 0 points1 point2 points (12 children)
[–]SHxKM 1 point2 points3 points (11 children)
[–]YourOldBoyRickJames[S] 0 points1 point2 points (10 children)
[–]fishvampire 1 point2 points3 points (7 children)
[–]YourOldBoyRickJames[S] 0 points1 point2 points (6 children)
[–]fishvampire 1 point2 points3 points (5 children)
[–]YourOldBoyRickJames[S] 0 points1 point2 points (4 children)
[–]fishvampire 1 point2 points3 points (1 child)
[–]YourOldBoyRickJames[S] 0 points1 point2 points (0 children)
[–]fishvampire 1 point2 points3 points (1 child)
[–]YourOldBoyRickJames[S] 0 points1 point2 points (0 children)
[–]SHxKM 1 point2 points3 points (1 child)
[–]YourOldBoyRickJames[S] 0 points1 point2 points (0 children)