Export to folder : different name each day

Solved!
bored_panda
Level 2
Export to folder : different name each day
I'm using an "export to folder" recipe to create a CSV that can then be used by other components. I'd like the CSVs to be named depending on the day they are exported :

- export_2017-01-25.csv
- export_2017-01-26.csv
- export_2017-01-27.csv

How can I do so ?
0 Kudos
1 Solution
cperdigou
Dataiker Alumni

One way of doing this is by using a python recipe on the dataset you wish to export, with a folder as output. In the recipe you can use the following code:




# -*- coding: utf-8 -*-
import dataiku
import pandas as pd, numpy as np
from dataiku import pandasutils as pdu

# Recipe inputs
input_dataset_name = dataiku.Dataset("input_dataset_name")
input_dataset_name_df = input_dataset_name.get_dataframe()

# Recipe outputs
folder_name = dataiku.Folder("folder_id")
folder_name_path = folder_name.get_path()

import time
current_day = time.strftime("%Y-%m-%d")
input_dataset_name_df.to_csv(path_or_buf=folder_name_path+"export_"+current_day+".csv", index=False)


 



Note that the first lines (input dataset, output folder etc) are all generated by DSS. So you should only add the last 3 lines of this code to your recipe, and change "input_dataset_name_df" and "folder_name_path" with the proper name.



 

View solution in original post

2 Replies
cperdigou
Dataiker Alumni

One way of doing this is by using a python recipe on the dataset you wish to export, with a folder as output. In the recipe you can use the following code:




# -*- coding: utf-8 -*-
import dataiku
import pandas as pd, numpy as np
from dataiku import pandasutils as pdu

# Recipe inputs
input_dataset_name = dataiku.Dataset("input_dataset_name")
input_dataset_name_df = input_dataset_name.get_dataframe()

# Recipe outputs
folder_name = dataiku.Folder("folder_id")
folder_name_path = folder_name.get_path()

import time
current_day = time.strftime("%Y-%m-%d")
input_dataset_name_df.to_csv(path_or_buf=folder_name_path+"export_"+current_day+".csv", index=False)


 



Note that the first lines (input dataset, output folder etc) are all generated by DSS. So you should only add the last 3 lines of this code to your recipe, and change "input_dataset_name_df" and "folder_name_path" with the proper name.



 

RomanaK
Level 1

Hi,

is  there a way how to solve this issue without python code? I have similar situation in which a file is exported with a suffix based on local variable. However this flow will be operated by a Data Analyst, hence I don't want to use any python code. 

Many thanks,

Romana