Is there a way to iterate over multiple dataframes to write them to multiple excel sheets with formatting?How to iterate over rows in a DataFrame in Pandas?Combine two loop into onePandas: Iterate through a list of DataFrames and export each to excel sheetsHow to multiply every column of one Pandas Dataframe with every column of another Dataframe efficiently?Create dataframes in for loop from multiple Excel workbooks based on worksheet name?How to write to separate excel worksheets within the same workbook in a for loop?Combining Excel worksheets over multiple loopsWrite data to to an excel sheet created in xlsxwriter in pythonIterate through MultiindexDynamically import EXCEL sheets and assign them to DataFrames in Python using pandas

From where do electrons gain kinetic energy through a circuit?

Can I submit a paper computer science conference using an alias if using my real name can cause legal trouble in my original country

Why is su world executable?

What allows us to use imaginary numbers?

Tikz: The position of a label change step-wise and not in a continuous way

My new Acer Aspire 7 doesn't have a Legacy Boot option, what can I do to get it?

Unconventional examples of mathematical modelling

Would getting a natural 20 with a penalty still count as a critical hit?

What are some tips and tricks for finding the cheapest flight when luggage and other fees are not revealed until far into the booking process?

μονάδαι as plural form of μονάς

What would cause a nuclear power plant to break down after 2000 years, but not sooner?

Best model for precedence constraints within scheduling problem

How does the illumination of the sky from the sun compare to that of the moon?

Radix2 Fast Fourier Transform implemented in C++

Rotate List by K places

What should I do with the stock I own if I anticipate there will be a recession?

Programming a recursive formula into Mathematica and find the nth position in the sequence

Reducing contention in thread-safe LruCache

Are there any rules on how characters go from 0th to 1st level in a class?

Existence of a certain set of 0/1-sequences without the Axiom of Choice

Why does this image of cyclocarbon look like a nonagon?

Is it alright to say good afternoon Sirs and Madams in a panel interview?

May the tower use the runway while an emergency aircraft is inbound?

Why should P.I be willing to write strong LOR even if that means losing a undergraduate from his/her lab?



Is there a way to iterate over multiple dataframes to write them to multiple excel sheets with formatting?


How to iterate over rows in a DataFrame in Pandas?Combine two loop into onePandas: Iterate through a list of DataFrames and export each to excel sheetsHow to multiply every column of one Pandas Dataframe with every column of another Dataframe efficiently?Create dataframes in for loop from multiple Excel workbooks based on worksheet name?How to write to separate excel worksheets within the same workbook in a for loop?Combining Excel worksheets over multiple loopsWrite data to to an excel sheet created in xlsxwriter in pythonIterate through MultiindexDynamically import EXCEL sheets and assign them to DataFrames in Python using pandas






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








1















I am working in pandas with 8 data frames and wish to write each of them to their own sheet in an Excel workbook. I also would like to apply formatting to each of the sheets as well. I am able to do it if I copy and paste the code 8 times, and adjust for the sheet name. However I was attempting to clean up the code by using a for loop to iterate through my data frames. However I end up with the:
TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed.



with pd.ExcelWriter('Excel_Test.xlsx') as writer:
df_list = [df_1 ,df_2 ,df_3 ,df_4 ,df_5 ,df_6 ,df_7 ,df_8]
for sheet in df_list:
sheet.to_excel(writer, sheet_name=sheet, index=False)
worksheet = writer.sheets[sheet]
worksheet.set_zoom(80)
worksheet.set_column('A:A', 14)
worksheet.set_column('B:B', 50)
worksheet.set_column('C:C', 30)
worksheet.set_column('D:D', 30)
worksheet.set_column('E:E', 25)
worksheet.set_column('F:F', 20)
money_format = writer.book.add_format('num_format': '$#,##0')
integer_format = writer.book.add_format('num_format': '#,##0')
worksheet.set_column('H:H', 9, integer_format)
writer.save()


The goal is to be able to have the for loop iterate through my list of dataframes and write each one to excel with the set formatting.










share|improve this question






























    1















    I am working in pandas with 8 data frames and wish to write each of them to their own sheet in an Excel workbook. I also would like to apply formatting to each of the sheets as well. I am able to do it if I copy and paste the code 8 times, and adjust for the sheet name. However I was attempting to clean up the code by using a for loop to iterate through my data frames. However I end up with the:
    TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed.



    with pd.ExcelWriter('Excel_Test.xlsx') as writer:
    df_list = [df_1 ,df_2 ,df_3 ,df_4 ,df_5 ,df_6 ,df_7 ,df_8]
    for sheet in df_list:
    sheet.to_excel(writer, sheet_name=sheet, index=False)
    worksheet = writer.sheets[sheet]
    worksheet.set_zoom(80)
    worksheet.set_column('A:A', 14)
    worksheet.set_column('B:B', 50)
    worksheet.set_column('C:C', 30)
    worksheet.set_column('D:D', 30)
    worksheet.set_column('E:E', 25)
    worksheet.set_column('F:F', 20)
    money_format = writer.book.add_format('num_format': '$#,##0')
    integer_format = writer.book.add_format('num_format': '#,##0')
    worksheet.set_column('H:H', 9, integer_format)
    writer.save()


    The goal is to be able to have the for loop iterate through my list of dataframes and write each one to excel with the set formatting.










    share|improve this question


























      1












      1








      1








      I am working in pandas with 8 data frames and wish to write each of them to their own sheet in an Excel workbook. I also would like to apply formatting to each of the sheets as well. I am able to do it if I copy and paste the code 8 times, and adjust for the sheet name. However I was attempting to clean up the code by using a for loop to iterate through my data frames. However I end up with the:
      TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed.



      with pd.ExcelWriter('Excel_Test.xlsx') as writer:
      df_list = [df_1 ,df_2 ,df_3 ,df_4 ,df_5 ,df_6 ,df_7 ,df_8]
      for sheet in df_list:
      sheet.to_excel(writer, sheet_name=sheet, index=False)
      worksheet = writer.sheets[sheet]
      worksheet.set_zoom(80)
      worksheet.set_column('A:A', 14)
      worksheet.set_column('B:B', 50)
      worksheet.set_column('C:C', 30)
      worksheet.set_column('D:D', 30)
      worksheet.set_column('E:E', 25)
      worksheet.set_column('F:F', 20)
      money_format = writer.book.add_format('num_format': '$#,##0')
      integer_format = writer.book.add_format('num_format': '#,##0')
      worksheet.set_column('H:H', 9, integer_format)
      writer.save()


      The goal is to be able to have the for loop iterate through my list of dataframes and write each one to excel with the set formatting.










      share|improve this question














      I am working in pandas with 8 data frames and wish to write each of them to their own sheet in an Excel workbook. I also would like to apply formatting to each of the sheets as well. I am able to do it if I copy and paste the code 8 times, and adjust for the sheet name. However I was attempting to clean up the code by using a for loop to iterate through my data frames. However I end up with the:
      TypeError: 'DataFrame' objects are mutable, thus they cannot be hashed.



      with pd.ExcelWriter('Excel_Test.xlsx') as writer:
      df_list = [df_1 ,df_2 ,df_3 ,df_4 ,df_5 ,df_6 ,df_7 ,df_8]
      for sheet in df_list:
      sheet.to_excel(writer, sheet_name=sheet, index=False)
      worksheet = writer.sheets[sheet]
      worksheet.set_zoom(80)
      worksheet.set_column('A:A', 14)
      worksheet.set_column('B:B', 50)
      worksheet.set_column('C:C', 30)
      worksheet.set_column('D:D', 30)
      worksheet.set_column('E:E', 25)
      worksheet.set_column('F:F', 20)
      money_format = writer.book.add_format('num_format': '$#,##0')
      integer_format = writer.book.add_format('num_format': '#,##0')
      worksheet.set_column('H:H', 9, integer_format)
      writer.save()


      The goal is to be able to have the for loop iterate through my list of dataframes and write each one to excel with the set formatting.







      python pandas






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 13:31









      pyhugspyhugs

      82 bronze badges




      82 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          0














          The sheet_name parameter should be a string, not the DataFrame object. Since you use the DataFrame object as a key in the writer.sheets dictionary, Python is trying to hash that.






          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function ()
            StackExchange.using("externalEditor", function ()
            StackExchange.using("snippets", function ()
            StackExchange.snippets.init();
            );
            );
            , "code-snippets");

            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "1"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55378467%2fis-there-a-way-to-iterate-over-multiple-dataframes-to-write-them-to-multiple-exc%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            The sheet_name parameter should be a string, not the DataFrame object. Since you use the DataFrame object as a key in the writer.sheets dictionary, Python is trying to hash that.






            share|improve this answer





























              0














              The sheet_name parameter should be a string, not the DataFrame object. Since you use the DataFrame object as a key in the writer.sheets dictionary, Python is trying to hash that.






              share|improve this answer



























                0












                0








                0







                The sheet_name parameter should be a string, not the DataFrame object. Since you use the DataFrame object as a key in the writer.sheets dictionary, Python is trying to hash that.






                share|improve this answer













                The sheet_name parameter should be a string, not the DataFrame object. Since you use the DataFrame object as a key in the writer.sheets dictionary, Python is trying to hash that.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 27 at 14:08









                sandrissandris

                9557 silver badges24 bronze badges




                9557 silver badges24 bronze badges





















                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







                    Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55378467%2fis-there-a-way-to-iterate-over-multiple-dataframes-to-write-them-to-multiple-exc%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                    SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

                    은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현