0

I want to align and organized data on Output. I have an excel file which has 2 sheets - Students, Anime. I already extracted data on excel files but my problem now is the output. This is what i've tried

file = pd.read_excel("src/doc/x1/students.xlsx", sheet_name=None)
print(file)

Output:

{'Students':       Name        Major     Block
0     Alex     Business  20200525
1     Clay  Engineering  20200526
2  Justine      Science  20200527, 'Anime':      Anime Name             Author
0     One Piece       Eiichiro Oda
1        Naruto  Masashi Kishomoto
2  Dragon Balls     Akira Toriyama}

How do I remove the Brackets on each end and align data like this

    'Students':       Name        Major     Block
                0     Alex     Business  20200525
                1     Clay  Engineering  20200526
                2  Justine      Science  20200527 

    'Anime':        Anime Name          Author
             0     One Piece        Eiichiro Oda
             1     Naruto           Masashi Kishomoto
             2     Dragon Balls      Akira Toriyama
1
  • Your input data looks not aligned ? How does initial dataframe looks like ? Commented Jun 1, 2020 at 7:29

1 Answer 1

1

Note that file is a dictionary where each key is the sheet's name and the value is the Dataframe from that sheet. you can use something like this and change the printing style to whatever you want:

for key, value in file.items():
    print(key + ":")
    print(value)
Sign up to request clarification or add additional context in comments.

5 Comments

almost ok but i want to export this as text file. how do i combine the key and value on one text file if i do print(value,file = open("mytext.txt", "w"))
When writing or reading from file please use with open(...) and then instead of printing just write it to the file
visit this thread to find out how to write a df to a .txt file
I already output the Key and Value but I want to combine it on one text file. How can i do it
visit the link I attached in the previous comment. It shows how to write a df into a .txt file. I am not sure if you can write all dataframes into one file together (if you can then great) but what you can do is write each dataframe into a temp .txt file, copy its content and write to the main .txt file from the temp one

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.