Advertisement
g96

Untitled

g96
Feb 23rd, 2022
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.91 KB | None | 0 0
  1. with open('1.txt') as f:
  2.     text = f.read().splitlines()
  3.  
  4. # split header row from data rows; discard garbage rows
  5. cols = text[3].split('|')
  6. data = text[5:]
  7.  
  8. # create df
  9. df = pd.Series(data).str.split('|', expand=True).rename(columns=dict(enumerate(cols))).iloc[:-2, 1:]
  10.  
  11. # remove leading/trailing whitespace
  12. df = df.apply(lambda s: s.str.strip(), axis=1)
  13. df.columns = df.columns.str.strip()
  14.  
  15. columns =['Order Qty (SL)','Confirmed Qty (SL)','Unconfirmed Qty (SL)','Cancelled Qty (SL)','Open Qty (SL)','Reserved Qty (SL)',
  16.  
  17.     'Fixed Qty (SL)','% Allocation (SL)','Delivered Qty (SL)','PGI Qty (SL)','Invoiced Qty (SL)',
  18.     'Net Unit Price','Confirmed Net Value (SL)','Dollars Shipped (SL)','% Shipped/Allocated (SL)']
  19.  
  20. df[columns] = df[columns].replace(',', '', regex=True).apply(pd.to_numeric) / 1000
  21.  
  22.  
  23. ###-----------------------------------------------------------------------------------------------------------------------
  24. # df_weekly = pd.read_csv('weekly.csv')
  25. df_mpim = pd.read_excel('MPIM Product Master.xlsx', sheet_name='OutputA')
  26. df_rejection = pd.read_excel(os.path.join(directory,'Rejection.xlsx'))
  27.  
  28. col_names_ama =['PC9','Account Seasonality']
  29. # col_names_dock = ['Materials', 'Amazon seasonality']
  30. df_ros = pd.read_excel(os.path.join(directory,'Amazon Seasonality.xlsx'),usecols=col_names_ama)
  31. df_dock =pd.read_excel(os.path.join(directory,'Dock seasonality.xlsx'))
  32. df_dock = df_dock.drop(df_dock.columns[0], axis=1)
  33.  
  34. print('1 Done')
  35.  
  36. # rename columns for pd.merge
  37. df.rename(columns={'Material': 'PC9'}, inplace=True)
  38. # df_ros.rename(columns={'Colorway Code' : 'PC9'}, inplace=True)  not applied anymore in new file
  39. df_ros.rename(columns={'Account Seasonality':'Seasonality'}, inplace=True)
  40. df.rename(columns={'Rej.Reason (SL)': 'Cancellation Code'}, inplace=True)
  41. df_dock.rename(columns={'Materials': 'PC9'}, inplace =True)
  42. df_dock.rename(columns={'Amazon seasonality':'Seasonality'}, inplace =True)
  43.  
  44. print('2 Done')
  45. #Add columns
  46. df_ros['Division']='10'
  47. df_dock['Division']='20'
  48. df_all = pd.concat([df_ros,df_dock])
  49.  
  50. print('3 Done')
  51. df1 = pd.merge(df, df_mpim[['PC9','Gender','Category', 'Product Description']], on='PC9', how='left')
  52. df2= pd.merge(df1,df_all[['PC9','Seasonality']], on='PC9', how='left')
  53. print(len(df2))
  54. df2.to_csv(directory +'check.csv', index=False, header=True)
  55. df3 = pd.merge(df2, df_rejection[['Cancellation Code', 'Description']], on='Cancellation Code',
  56.                    how='left')
  57.  
  58. df3['Seasonality']=df3['Seasonality'].replace(np.nan,'NIS')
  59.  
  60. print('4 done')
  61. # rename back columns
  62. df3.rename(columns={'PC9': 'Material',
  63.                      'Product Description': 'Product Name',
  64.                      'Seasonality' : 'Amazon Seasonality',
  65.                      'Description': 'Rej.Reason description',
  66.                     'Cancellation Code':'Rej.Reason (SL)'}, inplace =True)
  67.  
  68. df3.to_csv(directory + '3Weekly.csv', index=False, header= True)
  69. print("Finished VL1")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement