Python Recipe debugging-

Options
Oh_Lily
Oh_Lily Dataiku DSS Core Designer, Registered Posts: 12
edited July 16 in Using Dataiku

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

  • FlorentD
    FlorentD Dataiker, Dataiku DSS Core Designer Posts: 25 Dataiker
    edited July 17 Answer ✓
    Options

    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

Setup Info
    Tags
      Help me…