Updates related to data file exports.
This commit is contained in:
@@ -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',
|
||||
|
||||
Reference in New Issue
Block a user