Menu

Reading and Inspecting Data with pandas

Lesson 3: Reading and Inspecting Data with pandas

What is pandas?

pandas is a Python library for working with labelled tabular data.

Structure

Description

Analogy

SeriesOne labelled columnA single spreadsheet column
DataFrameA table of rows and columnsA whole spreadsheet or SQL table

Reading data from different sources:

Source

Function

CSVpd.read_csv('file.csv')
Excelpd.read_excel('file.xlsx', sheet_name='Sheet1')
JSONpd.read_json('file.json')
SQL databasepd.read_sql(query, connection)
Parquetpd.read_parquet('file.parquet')

Example

import pandas as pd
df = pd.read_csv('sales.csv')
print(df.head()) # first 5 rows
print(df.shape) # (rows, columns)
df.info() # prints directly; wrapping it in print() also outputs "None"

How it works

Method / attribute

What it shows

df.head(n) / df.tail(n)First / last n rows (default 5)
df.shapeNumber of rows and columns
df.info()Column names, data types, non-null counts, memory
df.dtypesData type of each column
df.sample(5)5 random rows (often more representative than head)

These checks help you understand the dataset before analysing it.

Other useful checks

Check

Code

What to look for

Column namesdf.columnsTypos, spaces, inconsistent naming
Numeric summarydf.describe()Negative values, extreme max values
Text summarydf.describe(include='object')Number of unique categories
Category countsdf['region'].value_counts(dropna=False)Misspellings, unexpected labels, missing values
Missing valuesdf.isna().sum()Columns with many gaps
Duplicatesdf.duplicated().sum()Repeated rows
Unique countdf['customer_id'].nunique()Number of distinct customers

Common mistakes

  • Assuming correct types:
    • Dates often load as text (object). Use parse_dates=['order_date'] in read_csv or pd.to_datetime().
    • Numbers with commas or currency symbols ('₹1,200') load as text and need cleaning.
  • Only looking at head()****: problems often sit further down the file.
  • Wrong delimiter or encoding: use sep=';' or encoding='utf-8' / 'latin-1' if the file looks garbled.

Data Analytics Tutorial



Learn via Video Course

Data Analysis and Processing with Python using Pandas - Data Science Course Logo

Data Analysis and Processing with Python using Pandas - Data Science Course

5 hrs



Get in Touch For Details