Save pandas dataframe in folder in Managed folder (XLSX files)

Kevin_dmausy
Kevin_dmausy Registered Posts: 3

Hello expert,

hope you're well. I'm writing to you because I can't fix this code to add my xlsx dataframe in a directory with today's date.

It works fine in csv but I need to store my files in xlsx.

I've tested to_excel but it doesn't work... the file remains at 0bytes.

Can you help me? Thanks a lot!

Answers

  • Turribeach
    Turribeach Dataiku DSS Core Designer, Neuron, Dataiku DSS Adv Designer, Registered, Neuron 2023 Posts: 2,166 Neuron

    Hi, please copy/paste your code in a code block (the </> icon in the message toolbar).

  • Kevin_dmausy
    Kevin_dmausy Registered Posts: 3
    edited July 17
    import dataiku
    import pandas as pd, numpy as np
    from dataiku import pandasutils as pdu
    
    
    from datetime import datetime
    todays_date = datetime.today().strftime('%Y-%m-%d')
    
    # Replace dataset anme
    
    Chroniques_2030 = dataiku.Dataset("Chroniques_2030")
    Chroniques_2030_df = Chroniques_2030.get_dataframe()
    
    #replace folder_id 
    managed_folder_id = "k7dA2Chq"
    
    # Write recipe outputs
    
    sub_path = str(todays_date) + '/'
    output_folder = dataiku.Folder(managed_folder_id)
    output_folder.upload_stream(sub_path + "Chroniques_2030.csv", Chroniques_2030_df.to_csv(index=False).encode("utf-8"))
  • Kevin_dmausy
    Kevin_dmausy Registered Posts: 3

    Thank you very much for your reply. Here's the code I use.

Setup Info
    Tags
      Help me…