Updating a variable from a dataset
Hello I have a dataset with only 1 row (but will change depending on other inputs) and I want to use it to update a global variable. I know I can use a python function in a scenario for this but can't quite work it out.
I have a dataset (my_dataset) that looks like this
Code. Year
122. 2021
I want to extract the 2021 figure and save it as a variable.
I know I can use code in a scenario along these lines
import dataiku
from dataiku.scenario import Scenario
scenario = Scenario()
df_data=dataiku.Dataset("my_dataset").get_dataframe(infer_with_pandas=False)
df_data = df_data['Year']
Scenario().set_project_variables("year_variable"=list(df_data)[0])
But I can't quite seem to get it working, any advice?
Operating system used: Mac OS
Answers
-
JordanB Dataiker, Dataiku DSS Core Designer, Dataiku DSS Adv Designer, Registered Posts: 296 Dataiker
Hi @akember182
,If you want to set a global variable, you'll need to use the set_global_variables method: https://developer.dataiku.com/latest/api-reference/python/scenarios-inside.html#dataiku.scenario.Scenario.set_global_variables
Please try the following:
scenario.set_global_variables(year_variable=list(df_data)[0])
Please let us know if you have any questions.
Thanks!
Jordan