Updates related to data file exports.

This commit is contained in:
Scott Idem
2024-05-23 10:41:09 -04:00
parent 6c5b120526
commit 0762ffcef8
2 changed files with 20 additions and 3 deletions

View File

@@ -382,6 +382,11 @@ def create_export_file(
data_dataframe = pandas.DataFrame(data_dict_list)
log.debug(data_dataframe)
missing_cols = [col for col in column_name_li if col not in data_dataframe.columns]
if missing_cols:
raise KeyError(f"The following columns are not found in the DataFrame: {', '.join(missing_cols)}")
# Need to deal with this error: KeyError("Not all names specified in 'columns' are found")
try:
if export_type == 'CSV':
log.info('Saving dataframe to CSV file')
@@ -390,7 +395,7 @@ def create_export_file(
tmp_file_path = os.path.join(subdir_path,filename_w_ext)
data_dataframe.to_csv(
full_dest_path,
# na_rep='NULL',
na_rep='NULL',
columns=column_name_li,
index=False,
# errors='ignore',
@@ -403,7 +408,7 @@ def create_export_file(
# This should ignore unknown columns
data_dataframe.to_excel(
full_dest_path,
# na_rep='NULL',
na_rep='NULL',
columns=column_name_li,
index=False,
# engine='openpyxl',