Adityabhaskar commited on
Commit
17b5798
·
verified ·
1 Parent(s): 0f4aab5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -4
app.py CHANGED
@@ -24,12 +24,24 @@ class HybridExcelQuerySystem:
24
  self.sheet_names = []
25
 
26
  def _pivot_numerical_data(self, df: pd.DataFrame) -> pd.DataFrame:
 
27
  header_row_index = 0
28
  df = df.T
29
- df.columns = df.iloc[header_row_index]
30
 
31
- # --- THIS IS THE FIXED LINE ---
32
- df = df.iloc[1:] # Keep all rows from the second row onwards
 
 
 
 
 
 
 
 
 
 
 
 
33
 
34
  df = df.reset_index().rename(columns={'index': 'Month'})
35
  df.columns = df.columns.str.strip().str.replace(r'[^a-zA-Z0-9_%]', '_', regex=True).str.replace('__', '_')
@@ -37,7 +49,6 @@ class HybridExcelQuerySystem:
37
  # Identify and convert numeric columns
38
  for col in df.columns:
39
  if col != 'Month':
40
- # Remove '%' and convert to numeric, coercing errors
41
  df[col] = df[col].astype(str).str.replace('%', '', regex=False)
42
  df[col] = pd.to_numeric(df[col], errors='coerce')
43
 
 
24
  self.sheet_names = []
25
 
26
  def _pivot_numerical_data(self, df: pd.DataFrame) -> pd.DataFrame:
27
+ """Pivots the special 'Numerical Data' sheet into a clean, usable format."""
28
  header_row_index = 0
29
  df = df.T
 
30
 
31
+ # Get potential new headers and de-duplicate them
32
+ new_headers = df.iloc[header_row_index].fillna('Unnamed')
33
+ seen = {}
34
+ final_headers = []
35
+ for col in new_headers:
36
+ if col in seen:
37
+ seen[col] += 1
38
+ final_headers.append(f"{col}_{seen[col]}")
39
+ else:
40
+ seen[col] = 0
41
+ final_headers.append(col)
42
+ df.columns = final_headers
43
+
44
+ df = df.iloc[1:]
45
 
46
  df = df.reset_index().rename(columns={'index': 'Month'})
47
  df.columns = df.columns.str.strip().str.replace(r'[^a-zA-Z0-9_%]', '_', regex=True).str.replace('__', '_')
 
49
  # Identify and convert numeric columns
50
  for col in df.columns:
51
  if col != 'Month':
 
52
  df[col] = df[col].astype(str).str.replace('%', '', regex=False)
53
  df[col] = pd.to_numeric(df[col], errors='coerce')
54