Python Pip install and pretty table - in this video I will walk you through how to install a package and how to use the pretty table module
Code for tutorial:-
---------------------------------------------------------------------------
from prettytable import PrettyTable
table1 = PrettyTable()
Adding rows one row at a time
table1.field_names = ["City name", "Area", "Population", "Annual Rainfall"]
table1.add_row(["Adelaide", 1295, 1158259, 600.5])
table1.add_row(["Brisbane", 5905, 1857594, 1146.4])
table1.add_row(["Darwin", 112, 120900, 1714.7])
table1.add_row(["Hobart", 1357, 205556, 619.5])
table1.add_row(["Sydney", 2058, 4336374, 1214.8])
table1.add_row(["Melbourne", 1566, 3806092, 646.9])
table1.add_row(["Perth", 5386, 1554769, 869.4])
print(table1)
print(table1.get_html_string())
print(table1.get_json_string())
print(table1.get_csv_string())
Adding all the rows at once
table2 = PrettyTable()
table2.field_names = ["City name", "Area", "Population", "Annual Rainfall"]
table2.add_rows(
[
["Adelaide", 1295, 1158259, 600.5],
["Brisbane", 5905, 1857594, 1146.4],
["Darwin", 112, 120900, 1714.7],
["Hobart", 1357, 205556, 619.5],
["Sydney", 2058, 4336374, 1214.8],
["Melbourne", 1566, 3806092, 646.9],
["Perth", 5386, 1554769, 869.4],
]
)
print(table2)
Adding data one column at a time
table3 = PrettyTable()
table3.add_column("City name",
["Adelaide","Brisbane","Darwin","Hobart","Sydney","Melbourne","Perth"])
table3.add_column("Area", [1295, 5905, 112, 1357, 2058, 1566, 5386])
table3.add_column("Population", [1158259, 1857594, 120900, 205556, 4336374, 3806092,
1554769])
table3.add_column("Annual Rainfall",[600.5, 1146.4, 1714.7, 619.5, 1214.8, 646.9,
869.4])
print(table3)
from prettytable import from_csv
with open("data.csv") as fi:
table4 = from_csv(fi)
table4.align = 'c'
print(table4)
https://pypi.org/project/prettytable/
On this page of the site you can watch the video online Python Pip install and pretty table : Python programming for beginners with a duration of hours minute second in good quality, which was uploaded by the user Brendan Callaghan 31 October 2022, share the link with friends and acquaintances, this video has already been watched 10,263 times on youtube and it was liked by 54 viewers. Enjoy your viewing!