Contents
Exploring a Dataset
Before analyzing a dataset, you should understand its structure, size, column names, and data types. Pandas provides several methods to inspect data quickly.
Viewing Rows and Dataset Information
import pandas as pd
df = pd.DataFrame({
"Employee": ["Aman", "Priya", "Ravi", "Neha"],
"Department": ["IT", "HR", "IT", "Finance"],
"Salary": [60000, 55000, 72000, 65000]
})
print(df.head(2))
print(df.tail(2))
print(df.shape)
print(df.columns)
- head() displays the first few rows.
- tail() displays the last few rows.
- shape returns the number of rows and columns.
- columns returns the column labels.
These methods help you inspect a dataset without printing every record.
Checking Data Types and Summary Statistics
print(df.info())
print(df.describe())
The info() method shows column data types, non-null counts, and memory usage. The describe() method provides descriptive statistics for numeric columns by default, including the count, mean, standard deviation, minimum, maximum, and quartiles.
You can inspect individual columns as well.
print(df["Salary"].dtype)
print(df["Department"].value_counts())
print(df.isnull().sum())
This helps identify categorical distributions, missing values, and potential data quality issues before further processing.
Python for Data Science
Vishalini A








