Python Code: 1. Create & Populate a Simple Table
Learn to create a Pixeltable directory and a basic table with string, integer, and float columns. Then, insert data and view the tables schema and contents.
1import pixeltable as pxt23# Optional: Clean up previous runs for a fresh start in interactive sessions.4# pxt.drop_dir('playground_core', force=True, ignore_not_found=True)5# pxt.create_dir('playground_core')67# Create a table for simple items8items_table = pxt.create_table(9 'playground_core.my_items',10 {11 'item_name': pxt.String,12 'quantity': pxt.Int,13 'price': pxt.Float14 }15)1617# Insert some data18items_table.insert([19 {'item_name': 'apple', 'quantity': 10, 'price': 0.5},20 {'item_name': 'banana', 'quantity': 20, 'price': 0.75},21 {'item_name': 'orange', 'quantity': 15, 'price': 0.6}22])2324print("--- Table Schema (from items_table.describe()) ---")25# print(items_table.describe()) # In a real session, this would print schema.26print("\\n--- Table Data (from items_table.head()) ---")27# print(items_table.head()) # In a real session, this shows first few rows.28# For the playground, the output panel simulates these results.
Output Panel
Click 'Run' or press Shift+Enter to see the output.
(OUTPUT IS SIMULATED FOR THIS PLAYGROUND)