Data Handling Using Pandas - I
Class 12 · Informatics Practices
4 ideas in Class 12 Informatics Practices, explained in plain words, with games and quizzes to practise.
Creating a Series
Part of: Series in Pandas
A Series is a single labelled column of values. From the list 10, 20, 30 you get labels 0, 1, 2 for free, and you can set your own labels like 3, 5, 1 or country names from a dictionary.
Why it matters. Real data arrives with roll numbers, dates and names attached. A Series keeps each value glued to its label so lookups stay correct.
Key words
- Series
- : A one-dimensional labelled set of values of one kind.
- Index
- : The label attached to each value in a Series.
- Default index
- : Automatic labels from 0 up to one less than the count.
- Dictionary keys
- : The key parts of pairs, used as labels when building a Series.
Try it in two minutes
- Write three fruit names in a column and number them 0, 1, 2 to show the default index.
- Renumber them 3, 5, 1 and ask which fruit label 5 picks.
- Pair three countries with capitals and show how the country becomes the label.
Try at home. List five family members with their ages, label each age by name, and read back two ages by label.
Reading Values from a Series
Part of: Series in Pandas
Values can be picked by their label or by their position, and the two can disagree when labels are shuffled. The head method shows the first rows, tail shows the last rows, and slicing grabs a middle chunk.
Why it matters. Checking the top, bottom and middle of data is how mistakes get spotted early. Label and position lookups answer different questions.
Key words
- Label lookup
- : Fetching a value using its index tag.
- Position lookup
- : Fetching a value by counting from the front, starting at 0.
- Head
- : Shows the first few members, five by default.
- Tail
- : Shows the last few members, five by default.
- Slicing
- : Picks a run of positions up to, but not including, the stop.
Try it in two minutes
- Label three boxes 3, 5, 1 and ask for box 1, then for the first box, to show the difference.
- Write numbers 10 to 19 and read the first two to show head.
- Read the last two to show tail.
- Cover all but the middle two numbers to show slicing.
Try at home. Number five pages of a notebook out of order, then fetch one page by its number and one by its position.
Series Attributes and Arithmetic
Part of: Describing and Combining Data
Attributes report facts about a Series: size counts the values and empty tells whether any exist. Arithmetic matches labels first, so adding series with labels a, b, c and a, b leaves label c without a partner, shown as a missing marker unless a fill value is supplied.
Why it matters. Combining marks, prices or scores from two lists only works when matching rows meet correctly. Knowing the fill trick keeps one missing label from wiping out a whole total.
Key words
- Size
- : The count of values stored in a Series.
- Empty
- : Reports True only when a Series holds no values.
- Label matching
- : Arithmetic pairs values carrying the same label.
- Fill value
- : A substitute number used where a label has no partner.
Try it in two minutes
- Count four beads together to show size, then check an empty box to show empty.
- Add price lists where one list lacks an item and spot the gap.
- Agree to treat the missing price as zero and redo the total.
- Multiply two small paired lists to show matching in action.
Try at home. Add two pocket-money lists with one week missing in one list, first leaving the gap and then filling it with zero.
Creating and Changing DataFrames
Part of: Describing and Combining Data
A DataFrame is a table with labelled rows and columns. Dictionary keys become column names, a list of dictionaries becomes rows with missing cells marked, dropping with axis 1 removes a column, and merging lines up two tables on a shared column.
Why it matters. Most real data is tabular: marks, prices, populations. Building and reshaping tables is the core skill behind every analysis.
Key words
- DataFrame
- : A two-dimensional table with labelled rows and columns.
- Column label
- : The name at the top of each DataFrame column.
- Axis
- : Chooses rows with 0 and columns with 1 when dropping.
- Merge
- : Joins two tables by lining up a shared column.
Try it in two minutes
- Write two fruits with prices as two lists and call them columns.
- Add a second row that lacks one price and mark the gap.
- Cross out the price column to show dropping with axis 1.
- Match two short lists by roll number to show merging.
Try at home. Tabulate three books with pages and prices, then drop the price column and rebuild it.
What your child will practise
- Creating a Series: Space Quick Fire (Quick Fire)
- Creating and Changing DataFrames: Candy Puzzle (Clue Puzzle)
- Creating and Changing DataFrames: Ocean Quick Fire (Quick Fire)
- Reading Values from a Series: Jungle Quick Fire (Quick Fire)
- Series Attributes and Arithmetic: Space Puzzle (Clue Puzzle)
- Quiz: Creating a Series (8 questions)
- Quiz: Creating and Changing DataFrames (8 questions)
- Quiz: Reading Values from a Series (8 questions)
- Quiz: Series Attributes and Arithmetic (8 questions)