joshuadunlop commited on
Commit
75e01a8
·
1 Parent(s): 879e393

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -5
app.py CHANGED
@@ -51,6 +51,9 @@ api_secret_key = st.sidebar.text_input("API Secret Key", "YOUR_API_SECRET_KEY",
51
  start_date = st.sidebar.date_input("Start Date", datetime.now() - timedelta(days=30))
52
  end_date = st.sidebar.date_input("End Date", datetime.now())
53
 
 
 
 
54
  # Fetch data button
55
  if st.sidebar.button("Fetch Data"):
56
  # Fetch data from ShareASale
@@ -60,26 +63,29 @@ if st.sidebar.button("Fetch Data"):
60
  # Parse the CSV data into a DataFrame
61
  df = parse_csv_to_df(ledger_data)
62
 
 
 
 
63
  # Filter rows where action is "Transaction Created"
64
  df_filtered = df.loc[df['action'] == 'Transaction Created']
65
 
66
  # Remove 'ledgerid' and 'transid' columns
67
- df_filtered = df_filtered.drop(columns=['ledgerid', 'transid', 'action'])
68
 
69
  # Display the DataFrame as a table
70
  st.write("Transaction Data")
71
  st.write(df_filtered)
72
 
73
- # Create a second table summing the impact for each unique merchantid
74
- df_sumif = df_filtered.groupby('merchantid')['impact'].sum().reset_index()
75
 
76
  # Calculate the total impact
77
  total_impact = df_sumif['impact'].sum()
78
 
79
  # Add a total row to the DataFrame
80
- total_row = pd.DataFrame({'merchantid': ['Total'], 'impact': [total_impact]})
81
  df_sumif = pd.concat([df_sumif, total_row], ignore_index=True)
82
 
83
  # Display the second DataFrame as a table
84
- st.write("Impact Summary by Merchant")
85
  st.write(df_sumif)
 
51
  start_date = st.sidebar.date_input("Start Date", datetime.now() - timedelta(days=30))
52
  end_date = st.sidebar.date_input("End Date", datetime.now())
53
 
54
+ # Load the merchantid to organisation name mapping
55
+ merchant_mapping = pd.read_csv('/mnt/data/a-599431.CSV') # Modify this path as needed
56
+
57
  # Fetch data button
58
  if st.sidebar.button("Fetch Data"):
59
  # Fetch data from ShareASale
 
63
  # Parse the CSV data into a DataFrame
64
  df = parse_csv_to_df(ledger_data)
65
 
66
+ # Merge with merchant mapping
67
+ df = pd.merge(df, merchant_mapping, on='merchantid', how='left')
68
+
69
  # Filter rows where action is "Transaction Created"
70
  df_filtered = df.loc[df['action'] == 'Transaction Created']
71
 
72
  # Remove 'ledgerid' and 'transid' columns
73
+ df_filtered = df_filtered.drop(columns=['ledgerid', 'transid', 'action', 'merchantid'])
74
 
75
  # Display the DataFrame as a table
76
  st.write("Transaction Data")
77
  st.write(df_filtered)
78
 
79
+ # Create a second table summing the impact for each unique organisation name
80
+ df_sumif = df_filtered.groupby('organisation name')['impact'].sum().reset_index()
81
 
82
  # Calculate the total impact
83
  total_impact = df_sumif['impact'].sum()
84
 
85
  # Add a total row to the DataFrame
86
+ total_row = pd.DataFrame({'organisation name': ['Total'], 'impact': [total_impact]})
87
  df_sumif = pd.concat([df_sumif, total_row], ignore_index=True)
88
 
89
  # Display the second DataFrame as a table
90
+ st.write("Impact Summary by Organisation")
91
  st.write(df_sumif)