Pandas Concepts

From NovaOrdis Knowledge Base
Jump to navigation Jump to search

External

Internal

Overview

pandas is a Python package that provides fast, flexible, and expressive data structures designed to make working with "relational" or "labeled" data both easy and intuitive. It aims to be the fundamental high-level building block for doing practical, real world data analysis in Python. As a result of having been built initially to solve finance and business analytics problems, Pandas features especially deep time series functionality and tools well suited for working with time-indexed data. Pandas is built in top of Numpy. Pandas provides two main data structures DataFrame and Series, which share concepts like axis and index. Pandas blends the array-computing ideas of NumPy with the kinds of data manipulation capabilities found in spreadsheets and relational databases, such as SQL. The Pandas name is derived from "panel data", an econometrics term for multidimensional structured datasets, and a play on the phrase "Python data analysis".

Import Convention

import pandas as pd

Axis

Both DataFrames and Series use the concept of axis. An axis means the direction in a bidimensional data matrix or a vector along which the means are computed. A DataFrame has a row axis and a column axis, while a Series has only one axis. The term comes from numpy, whose ndarray is used to implement the Panda Series. The indexes corresponding to a DataFrame or a Series axes are returned by the axes property.

Index

https://pandas.pydata.org/docs/reference/indexing.html

An index is an immutable sequence used to address data stored in a DataFrame or a Series, and it can be thought of as individual elements labels, for a Series or as the row labels for a DataFrame. By default, it consists in 0-based monotonically increasing integers (RangeIndex), but it can also consists in string labels, or in case of time series, by datetime instances (DatetimeIndex). Other indexes: CategoricalIndex, MultiIndex, IntervalIndex, TimedeltaIndex, PeriodIndex.

DataFrame and Series data elements can be addressed via both integral zero-based location, using the iloc[] syntax, and also via index values, using the loc[] syntax.

For details related to DataFrame and Series indexes, see:

DataFrame

DataFrame

Series

Series

Time Series Processing with Pandas

Time Series Processing with Panda

Data Types

String

Datetime

Date format when represented as string: YYYY-MM-DD, "2023-10-01".

Timestamp

Pandas has a replacement for Python datetime.datetime object, and that is pandas.Timestamp:

https://pandas.pydata.org/docs/reference/api/pandas.Timestamp.html#pandas.Timestamp

To create a Timestamp object:

import pandas as pd

ts = pd.to_datetime('2023-10-01')

Also see

Create a Time Series from CSV

Visualization

Both the DataFrame and Series have a plot() method, which delegates to matplotlib.

Data Loading

Excel

Pandas Excel

CSV

Pandas CSV

Datareader

pip3 install pandas_datareader