Python Export Dataframes To Excel

Поделиться
HTML-код
  • Опубликовано: 8 фев 2025

Комментарии • 7

  • @immanuelsuleiman7550
    @immanuelsuleiman7550 2 года назад +1

    I prefer to use a context manager
    with pd.ExcelWriter('path_to_file.xlsx', mode='w') as writer:
    for tab_num,df in enumerate(df_list):
    df.to_excel(writer, sheet_name=f"sheet_{tab_num}")

    • @codingwithlu
      @codingwithlu  2 года назад

      I like your approach. By placing df in list you can just loop over list to write out to each tab. Nice!

  • @tigreonice2339
    @tigreonice2339 2 года назад +1

    I want to do something like this. the data was taken with webscrapping, so i have 3 lists. I have a column of 1 type of fruit, another column of price and another of price per kg. I would like it to only write or save to a new array, list or dictionary if the fruit (with its price1 and price per kg) includes a specific word, for example fruit in 'box' or 'bulk'. do you know how i can do it?
    But if its fruit shampoo dont be write or save in excel column (it has not the word box or bulk).... or at least be written and the deleted that row

    • @codingwithlu
      @codingwithlu  2 года назад

      Hello Tigre, I think I see what you are trying to do, but can you provide sample of the 3 list you are reference and a sample of the exported version. You can email me at contact@iamlu.net

  • @vyron2080
    @vyron2080 2 года назад +1

    Hi Lu,
    Is it possible to export dataframe to existing and open xlsm ( macro enabled workbook ) ?
    Thanks

    • @codingwithlu
      @codingwithlu  2 года назад

      This shouldn't be a problem. I will make a video related to this.

    • @vyron2080
      @vyron2080 2 года назад

      @@codingwithluMany thanks for your response. I think I might have the answer with xlwings :)