SantanuBanerjee commited on
Commit
8cac918
·
verified ·
1 Parent(s): c3e7cfc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -9
app.py CHANGED
@@ -3,16 +3,37 @@ import pandas as pd
3
 
4
  def data_pre_processing(file_responses):
5
  # Financial Weights can be anything (ultimately the row-wise weights are aggregated and the corresponding fractions are obtained from that rows' total tax payed)
 
 
6
  try:
7
- # Define the columns to be processed
8
- columns = [
9
- '''Your financial allocation for Problem 1:
10
- Mention the percentage of your Tax Amount which you wish the Government would allocate through their annual budget, to implement a specific solution for your 1st problem.''',
11
- '''Your financial allocation for Problem 2:
12
- Mention the percentage of your Tax Amount which you wish the Government would allocate through their annual budget, to implement a solution specifically to your 2nd problem.''',
13
- '''Your financial allocation for Problem 3:
14
- Mention the percentage of your Tax Amount which you wish the Government would allocate through their annual budget, to implement a solution specifically to your 3rd problem.'''
15
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  file_responses = file_responses[[
17
  "Personal_TaxDirection_1_Wish",
18
  "Personal_TaxDirection_2_TaxWeightageAllocated"
 
3
 
4
  def data_pre_processing(file_responses):
5
  # Financial Weights can be anything (ultimately the row-wise weights are aggregated and the corresponding fractions are obtained from that rows' total tax payed)
6
+
7
+ # Define the columns to be processed
8
  try:
9
+
10
+ # Convert columns to numeric and fill NaN values with 0
11
+
12
+
13
+ file_responses['Personal_TaxDirection_1_TaxWeightageAllocated'] = pd.to_numeric(file_responses['Personal_TaxDirection_1_TaxWeightageAllocated'], errors='coerce').fillna(0)
14
+ file_responses['Personal_TaxDirection_2_TaxWeightageAllocated'] = pd.to_numeric(file_responses['Personal_TaxDirection_2_TaxWeightageAllocated'], errors='coerce').fillna(0)
15
+ file_responses['Personal_TaxDirection_3_TaxWeightageAllocated'] = pd.to_numeric(file_responses['Personal_TaxDirection_3_TaxWeightageAllocated'], errors='coerce').fillna(0)
16
+ file_responses['Latest estimated Tax payment?'] = pd.to_numeric(file_responses['Latest estimated Tax payment?'], errors='coerce').fillna(0)
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+ # Adding a new column 'Total Allocation' by summing specific columns by their names
25
+ file_responses['TotalWeightageAllocated'] = file_responses['Personal_TaxDirection_1_TaxWeightageAllocated'] + file_responses['Personal_TaxDirection_2_TaxWeightageAllocated'] + file_responses['Personal_TaxDirection_3_TaxWeightageAllocated']
26
+
27
+ # Calculating the actual TaxAmount to be allocated against each WISH (by rewriting the existing columns)
28
+ file_responses['Personal_TaxDirection_1_TaxWeightageAllocated'] = file_responses['Personal_TaxDirection_1_TaxWeightageAllocated'] * file_responses['Latest estimated Tax payment?'] / file_responses['TotalWeightageAllocated']
29
+ file_responses['Personal_TaxDirection_2_TaxWeightageAllocated'] = file_responses['Personal_TaxDirection_2_TaxWeightageAllocated'] * file_responses['Latest estimated Tax payment?'] / file_responses['TotalWeightageAllocated']
30
+ file_responses['Personal_TaxDirection_3_TaxWeightageAllocated'] = file_responses['Personal_TaxDirection_3_TaxWeightageAllocated'] * file_responses['Latest estimated Tax payment?'] / file_responses['TotalWeightageAllocated']
31
+
32
+
33
+
34
+
35
+
36
+
37
  file_responses = file_responses[[
38
  "Personal_TaxDirection_1_Wish",
39
  "Personal_TaxDirection_2_TaxWeightageAllocated"