Machine learning

Stage 1 · Lesson 5 of 8

pandas DataFrames: selecting, filtering and cleaning

Python for data

A is a table. Each column has a name and holds one type of data, and a single column on its own is called a Series. An index the rows.

Most real data work happens here. Learn to load a file with read_csv and look around with head, info, describe and value_counts. Then select columns, and keep only matching rows with a condition such as df[df['age'] > 30].

Use .loc to select by label and .iloc to select by position. Create new columns from existing ones, and fix types with astype and to_datetime. Vectorisation still applies: df['total'] = df['price'] * df['qty'] beats looping with iterrows every time.

Common trap like df[df.x > 0]['y'] = 1. It may change a temporary copy rather than df, so write df.loc[mask, 'y'] = 1 instead.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with· follow one of these

Practise

  • The Python, Pandas and Data Visualization micro courses, in browser notebooks

Keep handy

  • Start with 10 minutes to pandas, then look up indexing, groupby and reshaping

  • Quick NumPy, pandas and Matplotlib lookups with a try-it editor

Mark this stage as not done?