Pandas Python: Data Analysis with DataFrame and Series

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Pandas is a fundamental library for data analysis in Python, which has become the industry standard for processing structured information. Created by Wes McKinney in 2008, its name comes from the term "Panel Data" used in econometrics.

What is Pandas and Why is it So Important

Pandas is a powerful open-source library built on top of NumPy, providing high-level data structures and tools for fast and efficient data analysis. The library is especially effective for working with tabular data, time series, and any structured information.

Key Advantages of Pandas:

Versatility: Pandas supports working with various data formats — from CSV and Excel to JSON, SQL, HTML, and many others.

Performance: Thanks to optimized algorithms based on Cython and NumPy, the library delivers high speed when processing large volumes of data.

Intuitiveness: The library's syntax is designed to be as close to natural language as possible, making code readable and easy to learn.

Integration: Pandas integrates seamlessly with other Python ecosystem libraries — NumPy, Matplotlib, Scikit-learn, SciPy.

Applications of Pandas:

  • Data analysis and visualization — creating reports, dashboards, exploratory analysis
  • Machine learning — data preprocessing, feature engineering, dataset preparation
  • Financial analytics — time series analysis, calculating financial metrics
  • Business intelligence — report generation, sales analysis, KPIs
  • Scientific research — processing experimental data, statistical analysis
  • Web scraping — structuring and cleaning collected data

Installing and Importing Pandas

Installation via pip:

pip install pandas

Installation via conda:

conda install pandas

Importing the Library:

import pandas as pd
import numpy as np  # often used alongside pandas

The abbreviation pd has become a universal standard in the Python community and is used in all tutorials and documentation.

Core Data Structures: Series and DataFrame

Series — One-Dimensional Data with Indexes

A Series is a one-dimensional labeled array that can hold any data type: numbers, strings, boolean values, or Python objects.

# Creating a Series from a list
s = pd.Series([10, 20, 30, 40], index=['a', 'b', 'c', 'd'])

# Creating a Series from a dictionary
data = {'New York': 8336000, 'Los Angeles': 3898000, 'Chicago': 2746000}
population = pd.Series(data)

# Accessing elements
print(population['New York'])  # 8336000
print(population.iloc[0])      # first element

DataFrame — Two-Dimensional Tabular Data

A DataFrame is a two-dimensional data structure with labeled rows and columns, similar to a table in a relational database or an Excel spreadsheet.

# Creating a DataFrame from a dictionary
data = {
    'Name': ['Anna', 'Boris', 'Vika', 'Dmitry'],
    'Age': [25, 30, 22, 28],
    'City': ['New York', 'Chicago', 'Houston', 'New York'],
    'Salary': [80000, 95000, 60000, 75000]
}
df = pd.DataFrame(data)

# Creating a DataFrame with a custom index
df = pd.DataFrame(data, index=['emp1', 'emp2', 'emp3', 'emp4'])

Loading and Saving Data

Loading from Various Formats


  
  

Recommendations