Gumball2k5 commited on
Commit
d0e7eb9
·
verified ·
1 Parent(s): b7f9864

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +10 -4
src/streamlit_app.py CHANGED
@@ -6,16 +6,22 @@ import matplotlib.pyplot as plt
6
  # =========================
7
  # Utility: Load CSV with auto header detection
8
  # =========================
 
9
  def load_csv_auto(uploaded_file):
10
  """
11
- Load CSV file and automatically handle missing headers.
 
 
12
  """
13
- # First attempt: assume CSV has header
14
- df = pd.read_csv(uploaded_file)
15
 
16
- # If no numeric columns detected, retry without header
 
 
 
17
  if df.select_dtypes(include=[np.number]).shape[1] == 0:
18
  uploaded_file.seek(0)
 
 
19
  df = pd.read_csv(uploaded_file, header=None)
20
  df.columns = [f"column_{i}" for i in range(df.shape[1])]
21
 
 
6
  # =========================
7
  # Utility: Load CSV with auto header detection
8
  # =========================
9
+
10
  def load_csv_auto(uploaded_file):
11
  """
12
+ Robust CSV loader:
13
+ - Detects delimiter (comma / whitespace)
14
+ - Handles missing headers
15
  """
 
 
16
 
17
+ # ---- First attempt: auto-detect delimiter ----
18
+ df = pd.read_csv(uploaded_file, sep=None, engine="python")
19
+
20
+ # ---- If everything is object -> likely whitespace data ----
21
  if df.select_dtypes(include=[np.number]).shape[1] == 0:
22
  uploaded_file.seek(0)
23
+
24
+ # Try whitespace-separated
25
  df = pd.read_csv(uploaded_file, header=None)
26
  df.columns = [f"column_{i}" for i in range(df.shape[1])]
27