Exporting multiple dataframes with datetime stamp

Often while building data pipelines, you may require to export multiple dataframes, along with their name and the timestamp.

Let’s say you have 5 dataframes to be exported:

df_results, df_01, df_02, df_03 and df_staging

While exporting to CSVs, the name should be suffixed by YYYYmmdd format.

For e.g. df_01_20220802.csv if today is 02-Aug-2022

This can be done as follows:

dfs_to_export = ['df_results',  'df_01',  'df_02',  'df_03',  'df_staging']
for d in dfs_to_export:
    df_temp = eval(d)
    export_name = d + '_' + (pd.to_datetime("today").strftime(%Y%m%d)) + '.csv'
    df_temp.to_csv(export_name, index_col=False)