Tabulating Data in Python: A Beginner's Guide

Using Pandas DataFrames

·  Pandas, a powerful library for data manipulation and analysis, offers the DataFrame structure for tabulating data. ·  Import pandas and create a DataFrame to organize your data into rows and columns effortlessly.

Example Code Snippet

import pandas as pd # Sample data import pandas as pd data = {'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 30, 35], 'City': ['New York', 'Los Angeles', 'Chicago']} # Creating a DataFrame df = pd.DataFrame(data) print(df)

Tabulating with PrettyTable

It allows you to create stylish and readable tables from your data. Install PrettyTable and use its functions to display tabulated data with ease.

Example Code Snippet

Pip install prettytable from prettytable import PrettyTable # Sample data data = [['Alice', 25, 'New York'], ['Bob', 30, 'Los Angeles'], ['Charlie', 35, 'Chicago']] # Creating a PrettyTable object table = PrettyTable(['Name', 'Age', 'City']) # Adding data to the table for row in data: table.add_row(row) # Printing the table print(table)