Period 2 · Loading and Inspecting Data with Pandas
[video] Lecture video — Period 2: Loading and Inspecting Data with Pandas — /api/lesson-media/videos/4d3653ff-a3ca-4f63-bf8e-bb93c553e599-1794892494402-d264e17aa62de989.mp4
[markdown] content available only on the platform
[markdown] content available only on the platform
Flashcards · Loading and Inspecting Data with Pandas
DataFrame — A pandas table with labelled rows and columns.
`df = pd.read_csv("sales.csv")`
Series — A one-dimensional pandas object with an index, such as a single column.
`df["quantity"]` returns a Series.
pd.read_csv() — Reads a text file of comma-separated (or other separated) values into a DataFrame.
`pd.read_csv("sales.csv", sep=";")` for a semicolon file.
df.copy() — Creates an independent copy so that work does not change the original data.
`df = raw.copy()`
df.shape — An attribute giving the number of rows and columns as a tuple.
`(5, 4)` means 5 rows and 4 columns.
df.info() — A method that lists columns, data types and non-null counts.
Shows that each column has 5 non-null values.
KeyError — The error pandas raises when a column name in your code does not exist in the DataFrame.
Check `df.columns` for `"qty"` versus `"quantity"`.
Boolean mask — A Series of True/False values, one per row, used to select matching rows.
`mask = df["quantity"] >= 3`
df.loc[] — Selects rows and columns by label or mask, rows first and columns second.
`df.loc[mask, ["transaction_id", "unit_price"]]`
& and | operators — Element-wise AND and OR for combining conditions on pandas Series.
`(df["region"] == "North") & (df["quantity"] >= 3)`
[pdf] Lecture slides — Period 2 (PDF) — /api/lesson-media/pdfs/4d3653ff-a3ca-4f63-bf8e-bb93c553e599-1794873695070-dc264e04e480e479.pdf
