
Python Data Analysis Basics: Mastering Pandas Core Functions
- Development, Data Science
- Exien
- · Updated
Pandas is the core Python library for manipulating and analyzing tabular data, much like Excel spreadsheets or SQL tables. To get started, you need two data structures, Series and DataFrame, plus a handful of methods for loading files, selecting and filtering data, and handling missing values.
Why is Pandas the "Excel" of the Python data ecosystem?
Python became the dominant language in data science and machine learning thanks to an excellent ecosystem of libraries specialized in handling data, and Pandas sits at the center of that ecosystem.
Pandas lets you easily and powerfully manipulate and analyze tabular data in Python. It is no exaggeration to say that more than 80% of the work done by data analysts, including big data preprocessing, cleaning, filtering, and grouping, is done through Pandas.
How do you install and import Pandas?
Install the library with pip, then import it. By convention, it is imported using the alias pd.
# Install (Terminal)
# pip install pandas
# import
import pandas as pd
import numpy as np # Usually, numpy, a numerical calculation library, is also used.
What are Series and DataFrame in Pandas?
They are the two core data structures (containers) Pandas provides for storing data.
Series
Series is a data structure in the form of a one-dimensional array. It is easy to think of it as 'one column' of a table in Excel. It is similar to Python's basic list, but differs in having a label called an Index for accessing each value.
# Convert list to Pandas Series
data = ['Apple', 'Banana', 'Cherry']
s = pd.Series(data, index=['a', 'b', 'c'])
print(s)
# Output result:
# a Apple
# b Banana
# c Cherry
# dtype: object
DataFrame
DataFrame is a data structure in the form of a two-dimensional table. It is composed of rows and columns, and can be viewed as multiple Series gathered together. It is the structure you will handle most in real data analysis.
# Create DataFrame using dictionary
data = {
'Name': ['Alice', 'Bob', 'Charlie'],
'Age': [25, 30, 35],
'City': ['New York', 'London', 'Paris']
}
df = pd.DataFrame(data)
print(df)
# Output result:
# Name Age City
# 0 Alice 25 New York
# 1 Bob 30 London
# 2 Charlie 35 Paris
How do you load CSV and Excel files in Pandas?
Use pd.read_csv() and pd.read_excel(). In real work, rather than typing data into code, you load data saved as CSV or Excel files, and Pandas can read and write many formats.
# Read CSV file
df_csv = pd.read_csv('sales_data.csv')
# Read Excel file
df_excel = pd.read_excel('report.xlsx')
# Preview the first 5 rows (essential to understand what the data looks like!)
print(df_csv.head())
# Summary of overall information of the data frame (missing values, data type, etc.)
df_csv.info()
How do you select and filter data in Pandas?
Select columns by name, filter rows with conditions (Boolean Indexing), and pick specific positions with loc and iloc. Extracting only the information you want from a massive DataFrame is the core skill of Pandas.
Select a column
# Select only the 'Name' column (results are returned in Series format)
names = df['Name']
# When selecting multiple columns at the same time, group them into a list.
subset = df[['Name', 'City']]
Filtering rows that meet conditions (Boolean Indexing)
This works like the filter function in Excel, extracting only rows that satisfy specific conditions.
# Filter only people over 30 years old
over_30 = df[df['Age'] >= 30]
# When combining multiple conditions (AND: &, OR: |)
# Caution: You must use parentheses () for each conditional expression.
condition_df = df[(df['Age'] >= 30) & (df['City'] == 'London')]
Select data from specific location (loc, iloc)
loc[]: Select based on the 'label (name)' of the index.iloc[]: Select based on the 'position (integer number)' of the index.
# Get all data in row with index 0 (based on name)
row_0 = df.loc[0]
# Get data from row 0, column 1 (based on numbers)
val = df.iloc[0, 1]
How do you handle missing data in Pandas?
Check for missing values with isnull(), then either drop them with dropna() or fill them with fillna(). Real data is often empty (NaN, Not a Number) or full of invalid values, so handling missing values in the cleaning (preprocessing) stage is essential before analysis.
# Check if there are any missing values
print(df.isnull().sum())
# Delete rows containing at least one missing value
df_dropped = df.dropna()
# Fill missing values with another value (e.g. 0 or the mean value of a column)
mean_age = df['Age'].mean()
df_filled = df.fillna(mean_age)
What should you learn next?
Beyond these basics, Pandas has extensive built-in functions such as data merging (Merge, Concat), grouping and aggregation (GroupBy), and time series data processing.
Rather than trying to memorize every function from scratch, download a CSV dataset that interests you from Kaggle or a public data portal, load it, and experiment with it. Working with real data and wrestling with error messages is one of the best ways to learn.


















