Mar-09-2021, 11:13 AM
Can anyone tell me how I can put more than one list in table style display please? With columns and rows are nicely aligned.
Thanks.
Thanks.
Space between list and column alignment
|
Mar-09-2021, 11:13 AM
Can anyone tell me how I can put more than one list in table style display please? With columns and rows are nicely aligned.
Thanks.
Look back at your older Threadπ§
Mar-09-2021, 01:10 PM
(Mar-09-2021, 11:28 AM)snippsat Wrote: Look back at your older Threadπ§ However, my previous inquiry was for multi dimensional list. This is time is separate list I am trying to figure out.
Mar-09-2021, 01:53 PM
Show example of input and wanted output.
1: One way to display a data frame in the form of a table is by using the display() function of IPython.display.
filter_none brightness_4 # importing the modules from IPython.display import display import pandas as PD # creating a DataFrame dict = {'Name' : ['Martha', 'Tim', 'Rob', 'Georgia'], 'Maths' : [87, 91, 97, 95], 'Science' : [83, 99, 84, 76]} df = pd.DataFrame(dict) # displaying the DataFrame display(df) 2: In this example weβll use DataFrame.style. It returns a Styler object, which has useful methods for formatting and displaying DataFrames. filter_none brightness_4 # importing the module import pandas as pd # creating a DataFrame dict = {'Name' : ['Martha', 'Tim', 'Rob', 'Georgia'], 'Maths' : [87, 91, 97, 95], 'Science' : [83, 99, 84, 76]} df = pd.DataFrame(dict) # displaying the DataFrame df.style
Mar-15-2021, 01:48 PM
Mar-15-2021, 01:50 PM
(Mar-15-2021, 01:48 PM)rturus Wrote:(Mar-09-2021, 01:53 PM)snippsat Wrote: Show example of input and wanted output.
List is a data structure(internal use) and not meant to view like this,as that make no senseπ¦
For view take elements out data structure,then can figure a different way to view it. >>> list_a = [1,2,3,4,5] >>> list_b = ['d','h','f','s','g'] >>> lst = [] >>> lst.append([str(i) for i in list_a]) >>> lst.append(list_b) >>> >>> lst [['1', '2', '3', '4', '5'], ['d', 'h', 'f', 's', 'g']] >>> >>> for inner in lst: ... print(' | '.join((f"{word:4}" for word in inner))) ... 1 | 2 | 3 | 4 | 5 d | h | f | s | g >>> from tabulate import tabulate >>> >>> print(tabulate(lst, tablefmt="fancy_grid")) βββββ€ββββ€ββββ€ββββ€ββββ β 1 β 2 β 3 β 4 β 5 β βββββΌββββΌββββΌββββΌββββ€ β d β h β f β s β g β βββββ§ββββ§ββββ§ββββ§ββββ >>> print(tabulate(lst, tablefmt="pretty")) +---+---+---+---+---+ | 1 | 2 | 3 | 4 | 5 | | d | h | f | s | g | +---+---+---+---+---+ >>> print(tabulate(lst, tablefmt="simple")) - - - - - 1 2 3 4 5 d h f s g - - - - - >>> print(tabulate(lst, tablefmt="youtrack")) | 1 | 2 | 3 | 4 | 5 | | d | h | f | s | g |
Mar-17-2021, 04:47 PM
(Mar-15-2021, 08:21 PM)snippsat Wrote: List is a data structure(internal use) and not meant to view like this,as that make no senseπ¦ Thank you. This is very helpful. |
|