0

Currently, my python script tabulates this 2D array: [['Aquania', 'Castle Of Time', 'Colour Circuit', 'Comet Starway'], ['Crystal Dungeon', 'Ds Bowser Castle', 'Desert Fort', 'Dragon Burial Grounds'], ['Dreamworld Cloudway', 'Forest Creek', 'Gba Bowser Castle 2', 'Heart Of China'], ['Infernal Pipeyard', 'Jiyuu Village', 'Lunar Lights', 'Mushroom Valley'], ['Sahara Hideout', 'White Garden', 'White Garden', 'White Garden']] And it outputs it like this:

Cup 1                Cup 2             Cup 3                Cup 4
-------------------  ----------------  -------------------  ---------------------
Aquania              Castle Of Time    Colour Circuit       Comet Starway
Crystal Dungeon      Ds Bowser Castle  Desert Fort          Dragon Burial Grounds
Dreamworld Cloudway  Forest Creek      Gba Bowser Castle 2  Heart Of China
Infernal Pipeyard    Jiyuu Village     Lunar Lights         Mushroom Valley
Sahara Hideout       White Garden      White Garden         White Garden

However, I would like it to print with the first array in the 2d array going vertically so:

Cup 1
-------------------
Aquania
Castle Of Time
Colour Circuit
Comet Starway

and so on for all the other columns Is there a way to do this with tabulate?

Fear
  • 1

2 Answers2

0

Is this something that you're after?

import pandas as pd
def transpose_list_of_lists(list_of_lists):
    """
    This function converts a list of lists to a dataframe.

    :param list_of_lists: The list of lists to convert.
    :return: The dataframe.
    """
    return pd.DataFrame(list_of_lists).transpose()
Parvesh Kumar
  • 1,104
  • 7
  • 16
0

Not sure about tabulate but you could use pandas to do something like this.

import pandas as pd

data =[
    ["Aquania", "Castle Of Time", "Colour Circuit", "Comet Starway"],
    ["Crystal Dungeon", "Ds Bowser Castle", "Desert Fort", "Dragon Burial Grounds"],
    ["Dreamworld Cloudway", "Forest Creek", "Gba Bowser Castle 2", "Heart Of China"],
    ["Infernal Pipeyard", "Jiyuu Village", "Lunar Lights", "Mushroom Valley"],
    ["Sahara Hideout", "White Garden", "White Garden", "White Garden"],
]
df = pd.DataFrame(data)

df.index = [f'Cup{idx+1}' for idx in range(0, len(df))]

print(df.T)

             Cup1                   Cup2                 Cup3               Cup4            Cup5
0         Aquania        Crystal Dungeon  Dreamworld Cloudway  Infernal Pipeyard  Sahara Hideout
1  Castle Of Time       Ds Bowser Castle         Forest Creek      Jiyuu Village    White Garden
2  Colour Circuit            Desert Fort  Gba Bowser Castle 2       Lunar Lights    White Garden
3   Comet Starway  Dragon Burial Grounds       Heart Of China    Mushroom Valley    White Garden
norie
  • 9,609
  • 2
  • 11
  • 18
  • This looks good, would the numbers going down still be there? If so is it possible to remove them? – Fear Feb 09 '22 at 17:01