Python Recipe debugging-
Oh_Lily
Dataiku DSS Core Designer, Registered Posts: 12 ✭
Hello,
I am trying to export a folder with my result tables using a python recipe.
I am also trying to name each table differently.
Here is my code:
I keep getting this error when I run my code:
At line 43: <class 'TypeError'>: a bytes-like object is required, not 'str'
Any idea how to debug please?
Thanks in advance
def export_data(table,scope,liste_region): for region in liste_region : with export_DATA.get_writer(region + "/REPORT_AXIS_" +scope+ "_RG_"+ region + "_" + brand_filter + "_" + date_deb + "_" + date_fin + "_" + now + ".csv") as export_data: export_data.write(table[table['Region']== str(region)].to_csv(index=False))
Best Answer
-
Hi @Oh_Lily
,the trouble comes from
with export_DATA.get_writer(region + "/REPORT_AXIS_" +scope+ "_RG_"+ region + "_" + brand_filter + "_" + date_deb + "_" + date_fin + "_" + now + ".csv") as export_data: export_data.write(table[table['Region']== str(region)].to_csv(index=False))
You can't write directly a string, maybe putting an `encode()` will help to write, something like:
with export_DATA.get_writer(region + "/REPORT_AXIS_" +scope+ "_RG_"+ region + "_" + brand_filter + "_" + date_deb + "_" + date_fin + "_" + now + ".csv") as export_data: export_data.write(table[table['Region']== str(region)].to_csv(index=False).encode())
Hope this helps,
Best
Answers
-
Hello,
YES it works!!
thanks a lot for your help !!