Advertisement
g96

Untitled

g96
Feb 22nd, 2022
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.01 KB | None | 0 0
  1.  
  2. df_1 = pd.read_excel(os.path.join(directory,'copy.xlsm'), sheet_name= "weekly",header= None)
  3. df_1 = df_1.drop(df_1.columns[[0,1]], axis=1)
  4. df_1.columns = df_1.loc[3].rename(None)
  5. df_1 = df_1.drop(range(5))
  6.  
  7. df_1.to_csv(directory + '1.csv', index=False, header= True)
  8.  
  9. df_weekly=pd.read_csv(os.path.join(directory,'1.csv'))
  10.  
  11. columns =['Order Qty (SL)','Confirmed Qty (SL)','Unconfirmed Qty (SL)','Cancelled Qty (SL)','Open Qty (SL)','Reserved Qty (SL)',
  12.  
  13.     'Fixed Qty (SL)','% Allocation (SL)','Delivered Qty (SL)','PGI Qty (SL)','Invoiced Qty (SL)',
  14.     'Net Unit Price','Confirmed Net Value (SL)','Dollars Shipped (SL)','% Shipped/Allocated (SL)']
  15. df_weekly.loc[:len(df_1) - 2, columns] = df_weekly.loc[:len(df_1) - 2, columns].replace(',', '', regex=True).apply(pd.to_numeric) / 1000
  16.  
  17. df_weekly= df_weekly.drop(index=df_weekly.index[-2:])
  18.  
  19. # df_weekly.to_csv(directory + '1.csv', index=False, header= True)
  20. #Read CSV of SAP extract
  21.  
  22. # df_weekly=pd.read_csv(os.path.join(directory,'1.csv'), low_memory=False)
  23.  
  24. #read other files for merging
  25.  
  26. df_mpim = pd.read_excel('MPIM Product Master.xlsx', sheet_name='OutputA')
  27. df_rejection = pd.read_excel(os.path.join(directory,'Rejection.xlsx'))
  28. df_ros = pd.read_excel(os.path.join(directory,'A ROS.xlsx'), sheet_name='H221 ROS', header=6)
  29. df_dock =pd.read_excel(os.path.join(directory,'Dock A Seasonnality.xlsx'))
  30.  
  31. # rename columns for pd.merge
  32. df_weekly.rename(columns={'Material': 'PC9'}, inplace=True)
  33. df_ros.rename(columns={'Colorway Code' : 'PC9'}, inplace=True)
  34. df_ros.rename(columns={'Account Seasonality':'Seasonality'}, inplace=True)
  35. df_weekly.rename(columns={'Rej.Reason (SL)': 'Cancellation Code'}, inplace=True)
  36. df_dock.rename(columns={'Material': 'PC9'}, inplace =True)
  37. df_dock.rename(columns={'A Seasonality':'Seasonality'}, inplace =True)
  38.  
  39.  
  40. #Add columns
  41.  
  42. df_ros['Division']='10'
  43. df_dock['Division']='20'
  44. df_all = pd.concat([df_ros,df_dock])
  45. # Vlookup
  46.  
  47. df1 = pd.merge(df_weekly, df_mpim[['PC9','Gender','Category', 'Product Description']], on='PC9', how='left')
  48. #df2 = pd.concat([df1,df_ros[['PC9', 'Seasonality']],df_dock[['PC9','Seasonality']]]).groupby('PC9',as_index=False).first()
  49.  
  50. #df2 = pd.merge(df1, df_ros[['PC9','Account Seasonality']], on='PC9', how='left')
  51. #df3 =pd.merge(df2,df_rejection[['Rej.Reason (SL)', 'Rej.Reason description']], on='Rej.Reason (SL)', how='left')
  52. df2= pd.merge(df1,df_all[['PC9','Seasonality']], on='PC9', how='left')
  53. df3 = pd.merge(df2, df_rejection[['Cancellation Code', 'Description']], on='Cancellation Code',
  54.                    how='left')
  55.  
  56. df3['Seasonality']=df3['Seasonality'].replace(np.nan,'NIS')
  57.  
  58. # rename back columns
  59. df3.rename(columns={'PC9': 'Material',
  60.                      'Product Description': 'Product Name',
  61.                      'Seasonality' : 'A Seasonality',
  62.                      'Description': 'Rej.Reason description',
  63.                     'Cancellation Code':'Rej.Reason (SL)'}, inplace =True)
  64.  
  65. df3.to_csv(directory + '3Weekly.csv', index=False, header= True)
  66. print("Finished VL1")
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement