A pandas data frame is a two-dimensional grid held in memory, much like a relational database table. It gives data visible row and column labels and supports operations on whole columns or frames, often avoiding the loops needed with lists of lists. section 24.2.3
df = pd.DataFrame(grid, columns=["one", "two", "three"] ) print(df) one two three 0 1 2 3 1 4 5 6 2 7 8 9
A 3 × 3 grid becomes a data frame with numbered rows and named columns. section 24.2.3
Column selection uses the labels:
- `df["two"]` returns the values in one labeled column; they can be iterated over. section 24.2.3
- `df[["one", "three"]]` returns another data frame containing both columns. Calling `add(2)` on that result adds 2 to every displayed value. section 24.2.3
Data frames can also be loaded from CSV or JSON. Use `pd.read_csv("temp_data_01.csv", na_values=["Missing"])` to convert that file’s `Missing` entries to `NaN` as it loads. `to_csv(..., index=False)` saves without the row index; `to_json()` produces JSON. Some other input formats depend on libraries outside pandas. section 24.3.1
Clean a percentage column
For a column containing strings such as `'0.00%'`, `temp[17] = pd.to_numeric(temp[17].str.strip("%")).div(100)` removes the percent sign, converts the values to numbers, and expresses them as fractions. The operation applies down the column rather than requiring a row-by-row loop. section 24.3.2
Join and filter sales data
`pd.merge(calls, revenue, on=['Territory', 'Month'])` combines sales-call and revenue frames on their shared columns. From the resulting `calls_revenue`, `calls_revenue[calls_revenue.Territory == 3]` selects one territory; `calls_revenue['Call_Amount'] = calls_revenue.Amount / calls_revenue.Calls` adds a calculated column. section 24.4.1 section 24.4.2
Data frames are useful for loading, cleaning, selecting, and combining tabular data, but pandas is not always the best choice for datasets unsuited to it or for near-real-time processing. section 24.7


















