Spaces:
Sleeping
Sleeping
Update app.py
Browse files
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 |
-
|
| 8 |
-
columns
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 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"
|