Nexus Learn

Log in · Create free account

Module 4: Data analysis with pandas · 11 min

Loading data with pandas

pandas is the main Python package for tables of data. A table is called a DataFrame. A small example, made directly in code:

import pandas as pd

df = pd.DataFrame({
    "city": ["Lahore", "Karachi", "Multan", "Lahore"],
    "sales": [250, 400, 150, 300],
})
print(df)
print(df.shape)       # (4, 2)  rows, columns
print(df.head(2))     # first 2 rows

Real data usually comes from a file. read_csv loads a CSV file (a plain text table) in one line:

df = pd.read_csv("sales.csv")
df.info()        # columns, types, missing values
print(df.describe())   # count, mean, min, max of number columns
(free account needed to save progress)

← Working with JSON  |  Filter, group and sort →