DataFrames and the First Look
Identify what a row represents, load a table, and inspect its structure before analysing it.
First ask: what does one row represent?
| Cross-sectional data | Time-series data | |
|---|---|---|
| Compare | Different entities in the same period | The same entity or measure over time |
| Example | One row per customer this month | One row per day of a store’s sales |
| Row order | Usually no natural time sequence | Chronological order matters |
| Missing values | Consider comparable entities and the variable’s distribution | Respect time and what was known then |
| Train/test split | Random split can suit independent entities | For forecasting: earlier train, later test |
Our order-line table contains transactions. Aggregating sales by day creates a time series.
A Series is one labelled variable. A DataFrame places related Series in columns and gives them a shared row index.
Read across a row for one observation. Read down a column for one variable. Index labels identify rows; numerical positions count from 0.

pd.DataFrame({...}) uses dictionary keys as column names and lists as column values. Supply an index= when meaningful row labels are available.
Change one price, then run the box again. Check which cell changes.
A CSV stores a table as text separated by commas. pd.read_csv() returns a DataFrame. The first line normally supplies column names.
Attributes describe the table and have no parentheses. .shape is (rows, columns); .columns and .index contain labels; .dtypes gives one data type per column.
Methods perform a task and use parentheses. .head(2) returns the first two rows. .tail(2) returns the last two. .info() prints a structural summary.
.info() prints its report; avoid wrapping it in print(...), which would also print its return value, None.
Quantity is numerical, Store is categorical, and Date initially contains text. A number-like code may still be an identifier. Data type and business meaning both matter.
Print the row count, return the final two records, and name the column containing unit prices. Explain whether the index identifies stores or orders.
Hint: .shape[0], .tail(2), and .columns. Expected: four rows, last labels C and D, prices in Price.
Prof. Xuhu Wan · HKUST ISOM · Introduction to Business Analytics