Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -96,12 +96,11 @@ def process_file(file_obj):
|
|
| 96 |
|
| 97 |
# Handle NaN/Inf values before writing to Excel
|
| 98 |
processed_data = processed_data.replace([np.inf, -np.inf], np.nan)
|
|
|
|
| 99 |
|
| 100 |
# Save the processed data to a BytesIO stream using XlsxWriter
|
| 101 |
output = BytesIO()
|
| 102 |
-
|
| 103 |
-
workbook_options = {'nan_inf_to_errors': True}
|
| 104 |
-
writer = pd.ExcelWriter(output, engine='xlsxwriter', options=workbook_options)
|
| 105 |
processed_data.to_excel(writer, index=False, sheet_name='Directors')
|
| 106 |
|
| 107 |
# Get the xlsxwriter workbook and worksheet objects
|
|
@@ -127,6 +126,9 @@ def process_file(file_obj):
|
|
| 127 |
for col_num, value in enumerate(row):
|
| 128 |
column_name = processed_data.columns[col_num]
|
| 129 |
if column_name != 'Name':
|
|
|
|
|
|
|
|
|
|
| 130 |
worksheet.write(idx + 1, col_num, value)
|
| 131 |
|
| 132 |
# Close the writer and save the Excel file to BytesIO
|
|
|
|
| 96 |
|
| 97 |
# Handle NaN/Inf values before writing to Excel
|
| 98 |
processed_data = processed_data.replace([np.inf, -np.inf], np.nan)
|
| 99 |
+
processed_data = processed_data.fillna('')
|
| 100 |
|
| 101 |
# Save the processed data to a BytesIO stream using XlsxWriter
|
| 102 |
output = BytesIO()
|
| 103 |
+
writer = pd.ExcelWriter(output, engine='xlsxwriter')
|
|
|
|
|
|
|
| 104 |
processed_data.to_excel(writer, index=False, sheet_name='Directors')
|
| 105 |
|
| 106 |
# Get the xlsxwriter workbook and worksheet objects
|
|
|
|
| 126 |
for col_num, value in enumerate(row):
|
| 127 |
column_name = processed_data.columns[col_num]
|
| 128 |
if column_name != 'Name':
|
| 129 |
+
# Replace NaNs or Infs with empty strings
|
| 130 |
+
if pd.isnull(value) or value in [np.inf, -np.inf]:
|
| 131 |
+
value = ''
|
| 132 |
worksheet.write(idx + 1, col_num, value)
|
| 133 |
|
| 134 |
# Close the writer and save the Excel file to BytesIO
|