I'm trying to print a data frame to a log file, but the columns are misaligned. I came up with this solution to get the dataframe columns and row as a list, and then convert the columns and floating point data to strings, but there must be a better way to do this.
logging.error(f'Quality Metrics for Reconstructed File are Lower than Reference!!!')
print(df.shape)
columns = df_res.columns
msg = ' '.join(columns)
print(msg)
logging.error(msg)
data = df_res.iloc[0,:].tolist()
msg = ' '.join(map(str, data))
print(msg)
logging.error(msg)```
This is what the log file looks like.
2022-08-24 16:03:49,084 [ERROR] mse_avg mse_r mse_g mse_b psnr_avg psnr_r psnr_g psnr_b
2022-08-24 16:03:51,263 [ERROR] 0.02 0.01 0.03 0.01 65.44 67.82 62.78 67.82
You can see that the columns are not aligned correctly. Any advice on a better way to do this so that my log output is properly formatted?