E ExamMaster

Engineering Python · NumPy & pandas Basics

Series and DataFrames

In Engineering Python because tabular labs use labelled columns — Series and DataFrame are how pandas names those tables.

A Series is a labelled 1-D array. A DataFrame is a table: columns are Series sharing an index. Build small frames from dicts of lists.

  • Engineering Python
  • Medium level
  • 4 concepts

1Series

`pd.Series([..], index=[..])` pairs values with labels. Printing shows both.

Figure. pd.Series([1.2, 3.4], index=['a', 'b']) pairs each value with a label. Print shows index a with 1.2 and index b with 3.4.

Series

import pandas as pd
s = pd.Series([1.2, 3.4], index=['a', 'b'])
print(s)
What is a pandas Series?
  1. A labelled one-dimensional array
  2. A neural network
  3. A JSON file format

Series = values + index.

2DataFrame from a dict

`pd.DataFrame({'col': [...]})` builds a table. Columns are named; rows are examples.

Figure. pd.DataFrame({'temp_c': [20, 21], 'site': ['A', 'B']}) is a two-column table. Columns are named; each row is one example.

Takeaway

  1. Idea`pd.DataFrame({'col': [...]})` builds a table. Columns are named; rows are examples.

DataFrame

import pandas as pd
df = pd.DataFrame(
    {'temp_c': [20, 21], 'site': ['A', 'B']}
)
print(df)
In pandas, what is a DataFrame structurally?
  1. A 2D tabular data structure with labelled rows (index) and labelled columns
  2. A 1D homogeneous array with integer-only indexing
  3. An immutable binary file storage buffer
  4. A non-linear graph database node collection

A pandas DataFrame is a 2D labelled data structure with columns of potentially different types.

3Peeking at a frame

`.head()` shows the first rows; `.shape` and `.dtypes` summarise structure. Use them before plotting or modelling.

Figure. Before plotting or modelling, peek: .head() is the first rows, .shape and .dtypes summarise the frame's structure.

Takeaway

  1. Idea`.head()` shows the first rows; `.shape` and `.dtypes` summarise structure. Use them before plotting or modelling.

4Lab: build a tiny DataFrame

Construct a two-column frame and print it.

Figure. pd.DataFrame({'x': [1, 2, 3], 'y': [10, 20, 30]}) prints a two-column frame. The middle y value is 20.

Takeaway

  1. IdeaConstruct a two-column frame and print it.

Coding lab. Build a DataFrame runs in the app, with checks on your output.

Notes

  • In Engineering Python because tabular labs use labelled columns — Series and DataFrame are how pandas names those tables.
  • `pd.Series([..], index=[..])` pairs values with labels. Printing shows both.
  • `pd.DataFrame({'col': [...]})` builds a table. Columns are named; rows are examples.

Exam traps & shortcuts

  • Run one cell at a time and read stdout before changing more lines.
  • Names are labels for values; rebinding a name does not rewrite old prints.

Recap

Series are labelled vectors; DataFrames are column tables; head before modelling.

Series
`pd.Series([..], index=[..])` pairs values with labels. Printing shows both.
DataFrame from a dict
`pd.DataFrame({'col': [...]})` builds a table. Columns are named; rows are examples.
Peeking at a frame
`.head()` shows the first rows; `.shape` and `.dtypes` summarise structure. Use them before plotting or modelling.
Lab: build a tiny DataFrame
Construct a two-column frame and print it.

Practise Series and DataFrames

Reading is free and needs no account. Practice, mocks and progress live in the app.

  • A 2-question practice set that ends the chapter
  • 2 quick checks with worked explanations
  • Timed mocks scored with the real marking scheme
  • Readiness tracked per topic, kept on your device
Continue with Google — freeNo card, no trial. Works offline once installed.