Accessing Fields by Name in NumPy Structured Arrays
📖 Scenario: You work in a small store and keep track of products using a table with columns for product name, price, and quantity.
🎯 Goal: You will create a structured NumPy array to store product data, then access the price field by its name to see the prices of all products.
📋 What You'll Learn
Create a NumPy structured array with fields 'name', 'price', and 'quantity'.
Use a configuration variable to select the field name 'price'.
Access the 'price' field from the structured array using the field name.
Print the prices of all products.
💡 Why This Matters
🌍 Real World
Stores and businesses often keep product data in tables with named columns. Accessing fields by name helps quickly get specific information like prices or quantities.
💼 Career
Data scientists and analysts use structured arrays or tables to organize data. Knowing how to access fields by name is essential for data cleaning, analysis, and reporting.
Progress0 / 4 steps