Table

A table is a collection of related data held in a structured format. It consists of fields (columns), and rows.

Python Example

Python uses external library packages, such as PrettyTable, to support creating tables.

# Import the prettytable library.
from prettytable import PrettyTable

# Instantiate a PrettyTable object.
table = PrettyTable( )

# Define the table columns field names.
table.field_names = ["Company", "Industry", "Market Cap in Millions"]

# Add table rows.
table.add_row(["Cyber Web Tech", "Telecommunications", 34.5])
table.add_row(["Super Suite", "Software", 27.1])
table.add_row(["Great Burger", "Food", 47.8])

# Print the table.
print(table)

# The Pandas library can also be used to create and work with tables.
import pandas as pd

# Create a Pandas table, known as a DataFrame.
dataframe1 = pd.DataFrame({'A': [5, 7, 20, 13], 'B': [67, 12, 8, 57]})
print(dataframe1)

# Split a DataFrame by row/column value.
dataframe2 = dataframe1[dataframe1.A > 10]
print(dataframe2)