last day (15 days later) » 

00:02
Hello Emm.
Emm
Emm
Hi Marcelo--thanks for the extra help
When you open the Final_Output.xlsx file that was created with the pandas writer object what do you see?
Emm
Emm
a single sheet with the label Z
so I think with every loop it ran though it overwrite the sheets
What if you remove one of the to_excel calls that you have
Emm
Emm
rather than appending a new sheet to the workbook
it won't run
it doesn't recognize "writer" on its own with a coma
00:04
Can you elaborate more on that?
Is there an error message?
Emm
Emm
this is the error

18 writer, sheet_name= FileName
19

ValueError: too many values to unpack (expected 2)
when I just put sheet_name = FileName it runs fine
but still overwrites
What if you try the following:
FileName_List = ["AAPL", "GME", "MSFT", "NTDOY", "Z"]
# Create ExcelWriter object
with pd.ExcelWriter('Final_Output.xlsx') as writer:
    for FileName in FileName_List:
        ReadName = FileName + ".csv"
        Raw_Data = pd.read_csv(ReadName, sep = ",")


        # PRETEND THAT THERE'S CODE HERE THAT ACTUALLY MANIPULATES THE DATA

        # Write to excel sheet with writer object
        Raw_Data.to_excel(writer, sheet_name = FileName)
Emm
Emm
I also houses the for loop in the with loop that creates the excel too, though IDK if that's correct
yeah it still overwrite--I tried that first
Have you deleted the old Final_Output.xlsx file that was created before you ran the code?
Emm
Emm
no but I can try that and see what happens brb
no luck--came out complete blank this time too
actually the more I think of it-they all came out complete blank I think
but this time the sheet is not even named with anything
00:15
That is very odd. I have a hunch that it might be the manipulation code? So there are no sheets whatsoever? You're sure that the APPL, GME... etc sheets have data in them right?
Emm
Emm
yeah
before posting I did a print(Final_Data.head(10)
they all have data in them
I didn't manipulate the yahoo downloads either
just moved them straight from downloads to my directory
and that's all that's in the directory folder when starting the code alongside the PY file
mmmh, I have another idea.
Emm
Emm
I don't think it's the manipulation code though
at work I ran them off as to_excels creating individuals then realized its too many to send over email
so I have a bunch of excels right now in my directory at work because of the test run
What if you read the data, manipulate it and then put the dataframe in the list. After you read and manipulated all of your dataframes, write them into an excel sheet.
Emm
Emm
I actually considered that but wasn't certain how to do it
like I've tried automating the name and my python also errored out when I did that
so if you know how to automate into a dataframe--I'm game to try
00:23
Make sure you delete the Final_Output.xlsx file first
Emm
Emm
okay deleting now
what next?
FileName_List = ["AAPL", "GME", "MSFT", "NTDOY", "Z"]
# Create ExcelWriter object
df_list = []
for FileName in FileName_List:
    ReadName = FileName + ".csv"
    Raw_Data = pd.read_csv(ReadName, sep = ",")


    # PRETEND THAT THERE'S CODE HERE THAT ACTUALLY MANIPULATES THE DATA
    # Append to df list
    df_list.append(Raw_Data)

with pd.ExcelWriter('Final_Output.xlsx') as writer:
    for FileName, df in zip(FileName_List, df_list):
        # Write to excel sheet with writer object
        df.to_excel(writer, sheet_name=FileName)
Emm
Emm
OMG! GENIUS! Thank you! It worked! I really appreciate it!
Awesome!!!!!!
I'll update the answer
Emm
Emm
great thanks! This is going to make going in on Monday SO MUCH BETTER
00:26
Yay!!!!
The answer has been updated Emm. Good luck on Monday.
Have a good one.
 
6 hours later…
06:13
43 messages moved from Python
@Emm @MarceloPaco I've moved your discussion do this dedicated chatroom. I think it's much cleaner both for you and for all the people in the general Python chatroom to have this isolated here :)
let me know if you have any questions on the chat administration side
Thank you. Sorry about using the python general chat. Is there a guide on how to use the chats?
I don't think so... chat has long been an orphaned child. There's the faq but that's very little chat.stackoverflow.com/faq
There's a privelege for opening rooms, and another to speak in them (21 rep?). Room owners can manage access a bit in the room settings, move messages and kick users. Culture-wise it's very dependent on the chatroom. As long as stack overflow's terms and conditions/code of conduct are preserved it's OK. And chat must be in English.
Our local rules for the Python room are at sopython.com/chatroom. And multiline code formatting can be painful so we have a guide here sopython.com/wiki/…
There are also some posts on MSO/MSE with chat tags
And no worries :)

last day (15 days later) »