-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_csv.py
More file actions
34 lines (28 loc) · 1.21 KB
/
Copy pathtest_csv.py
File metadata and controls
34 lines (28 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import pandas as pd
import io
# Test the CSV file parsing
raw_data = open('S1_Venues_Cali(in).csv', 'rb').read()
for encoding in ['utf-8', 'latin-1', 'cp1252', 'iso-8859-1']:
try:
df = pd.read_csv(io.StringIO(raw_data.decode(encoding)))
print(f"\n=== Successfully decoded with: {encoding} ===")
print(f"Columns: {list(df.columns)}")
# Clean column names
cleaned_columns = []
for col in df.columns:
cleaned = str(col).strip().replace('\ufeff', '').replace('\u200b', '').replace('\ufffe', '')
print(f"Original: {repr(col)} -> Cleaned: {repr(cleaned)}")
cleaned_columns.append(cleaned)
df.columns = cleaned_columns
print(f"\nCleaned columns: {list(df.columns)}")
# Check for instagram
instagram_col = None
for col in df.columns:
print(f"Checking: {repr(col)} -> lower: {repr(col.lower())} -> 'instagram' in lower: {'instagram' in col.lower()}")
if 'instagram' in col.lower():
instagram_col = col
break
print(f"\nFound Instagram column: {instagram_col}")
break
except Exception as e:
print(f"Failed with {encoding}: {e}")