Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,8 +13,21 @@ def load_data(file_path):
|
|
| 13 |
parsed_data = []
|
| 14 |
with open(file_path, 'r', newline='', encoding='utf-8') as csvfile:
|
| 15 |
reader = csv.reader(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
return pd.DataFrame(parsed_data[1:], columns=parsed_data[0])
|
| 19 |
|
| 20 |
return custom_csv_parser(file_path)
|
|
@@ -66,4 +79,3 @@ if __name__ == "__main__":
|
|
| 66 |
main()
|
| 67 |
|
| 68 |
|
| 69 |
-
|
|
|
|
| 13 |
parsed_data = []
|
| 14 |
with open(file_path, 'r', newline='', encoding='utf-8') as csvfile:
|
| 15 |
reader = csv.reader(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)
|
| 16 |
+
header = next(reader)
|
| 17 |
+
parsed_data.append(header)
|
| 18 |
+
num_columns = len(header)
|
| 19 |
+
for line_number, row in enumerate(reader, start=1):
|
| 20 |
+
if len(row) == num_columns:
|
| 21 |
+
parsed_data.append(row)
|
| 22 |
+
else:
|
| 23 |
+
# Print the line number (0th value of the line)
|
| 24 |
+
print(f"Line number {line_number} (row 0th value: {row[0] if row else 'Empty'}) has mismatched columns")
|
| 25 |
+
# Handle rows with mismatched columns
|
| 26 |
+
if len(row) < num_columns:
|
| 27 |
+
row.extend([''] * (num_columns - len(row))) # Pad with empty strings
|
| 28 |
+
else:
|
| 29 |
+
row = row[:num_columns] # Truncate to the correct number of columns
|
| 30 |
+
parsed_data.append(row)
|
| 31 |
return pd.DataFrame(parsed_data[1:], columns=parsed_data[0])
|
| 32 |
|
| 33 |
return custom_csv_parser(file_path)
|
|
|
|
| 79 |
main()
|
| 80 |
|
| 81 |
|
|
|