FIT1043 · Introduction to Data Science
Introduction to Python for Data Science
Week 2 of Monash FIT1043 Introduction to Data Science puts Python and Jupyter notebooks to work as the unit's main analysis tool, centred on the pandas library: building and inspecting DataFrames, selecting and filtering rows, and grouping and aggregating. You are not asked to write code in the exam, but you ARE asked to READ a snippet and state what it returns, so the skill this week trains — reasoning precisely about a line of pandas — is directly examinable in Test 1 and the final. This chapter underpins Data Science Assignment 1, which is built in Python/Jupyter.
What this chapter covers
- 01Python as the most popular data-analytics language; coding in Jupyter notebooks (.ipynb = Interactive Python NoteBook)
- 02pandas DataFrame: a structure that stores tabular data; head(), tail(), sample(), .shape, .dtypes, .describe()
- 03Indexing and selection: df['col'], df.loc[...], boolean masks
- 04Boolean filtering and operator precedence: combining conditions with &, | and parentheses (the parenthesis trap)
- 05Derived columns: df['Total'] = df['Math'] + df['English']; averages from derived columns
- 06Reshaping and merging: pd.melt (wide to long); pd.merge on a key — inner join drops unmatched rows vs how='left' keeping all left rows
- 07Reading files and types: pd.read_csv / pd.read_excel; pd.to_datetime converting an object column to datetime64
- 08groupby and aggregation: reading what a groupby(...) expression returns before any aggregation is applied
Read a pandas groupby line and a boolean filter
- +1(a) groupby(['Sex','Class']) splits the data into groups by every Sex-Class combination, and ['Age'] selects the Age column within those groups. It only sets up the grouping on Age — no aggregation (no mean/count) has been applied yet, so nothing is summarised until you chain e.g. .mean().
- +1(b) The boolean mask keeps rows where Sex is 'female' AND Survived equals 1, so df.loc[...] returns the data for all female passengers who survived. The parentheses around each condition are required because & binds tighter than the comparison operators.
Key terms
- Jupyter notebook (.ipynb)
- An Interactive Python NoteBook: a browser document mixing runnable code cells, output and notes, used as FIT1043's main Python environment.
- pandas DataFrame
- A structure that stores tabular data (rows and named columns); the workhorse object for data wrangling in Python. Inspect it with head(), tail(), .shape, .dtypes and .describe().
- .loc / boolean mask
- Label-based selection: df.loc[mask] returns the rows where a boolean condition is True, e.g. (df['Sex']=='female') & (df['Survived']==1). Each condition needs parentheses because & binds tightly.
- groupby
- Splits a DataFrame into groups by one or more columns; on its own it applies NO aggregation — you must chain .mean(), .count() or .agg({...}) to summarise.
- melt / merge
- pd.melt reshapes wide data to long (columns become rows); pd.merge joins two frames on a key — an inner join drops unmatched rows, while how='left' keeps all left rows and fills missing values with NaN.
- pd.to_datetime
- Converts a column of the generic object dtype into datetime64, so dates can be sorted, differenced and grouped by time.
Introduction to Python for Data Science FAQ
Do I have to write Python code in the FIT1043 exam?
No. The unit is explicit that you will not be asked to write code in Test 1 or the final. However, you may be asked to READ a snippet and interpret it or state the output of a given line — so reading pandas fluently is exactly the examinable skill. Practise saying, in one sentence, what a groupby, .loc filter or merge returns.
What is the difference between an inner join and a left join in pandas?
pd.merge(a, b, on='key') defaults to an inner join, which keeps only rows whose key appears in both frames — unmatched rows are dropped. how='left' keeps every row of the left frame and fills the missing right-hand columns with NaN. The exam-friendly test case: a student with no matching height record disappears under an inner join but survives with NaN under a left join.
Why do I need parentheses in df.loc[(A) & (B)]?
Because in pandas the & operator binds more tightly than the comparison operators, so df['Sex']=='female' & df['Survived']==1 would be parsed wrongly. Wrapping each comparison in parentheses — (df['Sex']=='female') & (df['Survived']==1) — forces the comparisons to happen first. The same trap applies to combining conditions with |.
Can AI help me read pandas code for FIT1043?
Yes. Sia can take a line of pandas or an applied-session solution and walk through what each part does, build a tiny DataFrame to show the output, and quiz you on groupby-versus-groupby-plus-aggregation, step by step. It helps you understand and check your reading; it does not complete Assignment 1 for you, and Monash academic-integrity rules apply. Confirm details on Moodle.
Exam move
The examinable skill this week is reading pandas, not writing it, so rehearse with the Week 2 applied-session solution: cover the output, predict what each line returns in one sentence, then check. Drill the high-frequency idioms — a boolean .loc filter (with the parenthesis rule), a derived column, a melt, an inner vs left merge, and especially a groupby with and without a following aggregation (the classic MCQ tests that groupby alone summarises nothing). Because this material also builds Assignment 1, do the weekly quiz and keep a short 'what does this line return' cheat list you can revise before Test 1 and the final.
Working through Introduction to Python for Data Science in FIT1043? Sia is AskSia’s AI Information Technology tutor — ask any FIT1043 Introduction to Python for Data Science question and get a clear, step-by-step explanation grounded in how FIT1043 is taught and assessed. Read this chapter free, then take your hardest questions to Sia.