Introduction
Pandas is an open source python library for fast, flexible data analysis and manipulation.
Pandas allows users to import data from various file formats (comma-separated values, JSON, SQL, fits, etc.) and perform data manipulation operations, including cleaning and reshaping the data, summarizing observations, grouping data, and merging multiple datasets
With hundreds of functions and methods for data manipulation and analysis, it has become one of the most widely used tools in the world primarily for data analysis.
This article explores the most commonly used functions and methods for understanding, formatting, and visualizing data with the pandas package.
Reading data into Pandas
Pandas is capable of reading data from various file formats. In this case, we are reading our dataset in the file format csv.
The data is stored in a data structure called DataFrame which will defined by the variable name df.
import pandas as pd
file_name= "world_population.csv"
df=pd.read_csv(file_name)
Understanding the data format
In these step we are going to understand how these functions are of useful in data inspection.
- df.head()
- df.tail()
- df.info()
- df.describe()
- df.shape
1. df.head()
This function will show the first 5 rows in the DataFrame:
2. df.tail()
This function shows the last 5 rows of the DataFrame
3. df.info()
This function displays the coincise summarry of the DataFrame
4. df.describe()
This is used to display descriptive statistical information about the numerical columns in a DataFrame including descriptive statistics of the central tendacy and dispersion.
5. df.shape()
This displays the number of rows and columns in the DataFrame
Data Format
Choosing which data format is relevant and makes sure the DataFrame is in a format that can be easily understood.
df.info() shows each column's data type, so it is the first place to look for columns stored as the wrong type, such as numbers read as text.
Cleaning the data
Before analyzing, it is worth checking for three common problems: missing values, duplicates and inconsistent text.
Handling missing values
Use df.isnull().sum() to see where values are missing. If any are, you can drop the affected rows or fill the gaps with a sensible value:
Removing duplicates
Duplicate rows can distort totals. Check how many there are, then remove them:
df.duplicated().sum()
If there is no duplicated values, the dataset is ready to work with otherwise the duplicated values should be dropped
df= df.drop_duplicates(
Sorting, selecting and filtering data
To find the most populous countries, sort by population:
To select columns, pass their names in a list:
To filter rows, use a condition inside square brackets:
Visualization
Pandas works with Matplotlib, so you can create charts directly from a DataFrame or Series.
# Visualization
import matplotlib.pyplot as plt
top10 = df.nlargest(10, "2022 Population").set_index("Country")["2022 Population"]
top10.sort_values(ascending=False).plot(
kind="bar",
title="Top 10 Most Populous Countries (2022)"
)
plt.ylabel("Population")
plt.xlabel("Country")
plt.xticks(rotation=45, ha="right")
plt.tight_layout()
plt.show()
Conclusion
This article demonstrated a complete introductory data analysis workflow using Python and Pandas, with a world population dataset as a practical example. The analysis covered how to load and inspect data, understand its structure, clean column names, handle missing values and duplicates, examine data types, sort and filter records, and visualize population using Matplotlib.











Top comments (0)