pandas-ta Technical Analysis Library

0.4.71b0 · active · verified Sun Apr 12

pandas-ta is a comprehensive Python 3 library for technical analysis, extending Pandas Dataframes with a wide range of indicators. It's designed for quantitative researchers, traders, and investors, providing an easy-to-use API for applying financial indicators directly to Dataframes. The current version is 0.4.71b0 (beta), indicating active development and frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to load sample data, apply a single technical indicator (SMA) directly, and then use the `df.ta.strategy()` method to apply a collection of indicators. Note the behavior of `append=False` by default in `0.4.x` versions, meaning indicators are not automatically added to the original DataFrame unless explicitly handled.

import pandas as pd
import pandas_ta as ta
import io

# Sample financial data (usually loaded from CSV, API, etc.)
data = """Open,High,Low,Close,Volume
100,105,99,103,1000
103,108,102,107,1200
107,112,106,110,1100
110,115,109,114,1300
114,119,113,117,1400
117,122,116,120,1500
120,125,119,123,1600
123,128,122,127,1700
127,132,126,130,1800
130,135,129,133,1900
"""
df = pd.read_csv(io.StringIO(data))

# Extend pandas with pandas-ta and apply a strategy
# By default, indicators are not appended to the original DataFrame in v0.4+
# Use append=True if you want to modify the original df, or reassign.
# For quickstart, we'll demonstrate adding to a new df to show the result clearly

# Apply a single indicator (e.g., Simple Moving Average)
df['SMA_10'] = ta.sma(df['Close'], length=3) # Example length

# Apply a full strategy (e.g., 'All' or a custom one)
# By default, 'append=False' in v0.4+ for df.ta accessor.
# Let's create a new DataFrame to show the strategy results cleanly.
strat_df = df.copy()
strat_df.ta.strategy("All") # Applies a set of common indicators

print("DataFrame with SMA:")
print(df.tail())
print("\nDataFrame with 'All' strategy indicators (new columns only):")
print(strat_df.tail())
# To see only the newly added columns for strategy:
# print(strat_df.drop(columns=['Open', 'High', 'Low', 'Close', 'Volume']).tail())

view raw JSON →