Forum Discussion

bminehart's avatar
09-10-2024

Renamed Widget Categories and Exporting to CSV/Excel

Hello:

I'm doing something similar to what's described in this Community post. It works well when viewing the data in the Widget, however when I export the Widget to a CSV, the original names of the Categories are exported. Is there a way to modify the scripting in such a way that the new category names are kept intact upon export?

Thanks!

1 Reply

  • harikm007's avatar
    harikm007
    Data Warehouse

    Hi bminehart ,

    To address this, you can use the 'Add Transformation' option within your widget to rename categories.

    Here’s a step-by-step approach you can follow:

    1. Use 'Add Transformation' in the Widget:

    2. Script for Transformation:

      • In the Jupyter Notebook, under the transformation section, you can use the following script to rename your categories. Make sure to update the mapping variable to reflect your actual old and new category names. Be sure to replace 'Category' with the panel name of the column you added in the widget.

     

     

    mapping = {
        'old_name1': 'new_name 1', 'old_name2': 'new_name 2', 'old_name3': 'new_name 3', 'old_name4': 'new_name 4'
    }
    df_result = df_input
    df_result['Category'] = df_input['Category'].map(lambda x: mapping.get(x, x))

     

     

     This script maps the old category names to the new ones and ensures that the changes are applied correctly.  If a category name does not match any key in the mapping dictionary, it will remain unchanged.

    Thanks,

    Hari

    https://www.binextlevel.com/