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
Fatur Rahman S
  • 341
  • 1
  • 3
  • 10
JBA
  • 219
  • 4
  • 15

1 Answers1

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)
snatchysquid
  • 1,283
  • 9
  • 24
  • 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"))` – JBA Jun 01 '20 at 07:41
  • When writing or reading from file please use `with open(...)` and then instead of printing just write it to the file – snatchysquid Jun 01 '20 at 07:43
  • visit this [thread](https://stackoverflow.com/questions/41428539/data-frame-to-file-txt-python/41428596) to find out how to write a `df` to a `.txt` file – snatchysquid Jun 01 '20 at 07:54
  • I already output the Key and Value but I want to combine it on one text file. How can i do it – JBA Jun 01 '20 at 08:00
  • 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 – snatchysquid Jun 01 '20 at 08:07