ft-pandas-ta
ft-pandas-ta is an active Python library (version 0.3.16) that extends Pandas DataFrames with over 130 technical analysis indicators. It functions as an easy-to-use Pandas extension, allowing indicators to be called directly from DataFrames or as standalone functions, with reported correlation tested against TA-Lib. This project is a fork of the popular `pandas-ta` library, maintaining a healthy release cadence.
Common errors
-
ImportError: cannot import name 'NaN' from 'numpy'
cause The `ft-pandas-ta` library (or underlying `pandas-ta` module) is trying to import `NaN` from `numpy`, but modern NumPy (e.g., 2.0+) uses `nan` (lowercase).fixUpgrade `ft-pandas-ta` to 0.3.16 or newer (`pip install --upgrade ft-pandas-ta`). If the problem persists, you might need to downgrade `numpy` to an older version like `numpy==1.26.3` or manually edit the problematic `ft-pandas-ta` source file if a fix isn't available. -
KeyError: 'close'
cause An indicator function was called on a DataFrame, but the required 'close' column (or other OHLCV columns like 'open', 'high', 'low', 'volume') was not found.fixVerify that your DataFrame has columns named 'open', 'high', 'low', 'close', 'volume' (case-insensitive for the `.ta` accessor but explicit calls require exact names). Rename columns if necessary (e.g., `df.columns = df.columns.str.lower()`). -
AttributeError: 'DataFrame' object has no attribute 'ta'
cause The `pandas_ta` module was not imported, or it was imported in a way that did not activate the DataFrame extension. The `.ta` accessor is added to DataFrames upon importing `pandas_ta`.fixEnsure you have `import pandas_ta as ta` (or similar) at the beginning of your script. This import statement activates the `.ta` accessor for all Pandas DataFrames. -
TypeError: Cannot compare types '_____' and '_____' (for example, string and int) when performing operations involving indicator calculations.
cause Input columns for indicators contain mixed data types or non-numeric types (e.g., strings) where numbers are expected.fixInspect the `dtypes` of your DataFrame columns, especially those used in indicator calculations. Convert relevant columns to numeric types (e.g., `pd.to_numeric(df['column'], errors='coerce')`) and handle any `NaN` values that result from coercion.
Warnings
- breaking Older versions (prior to 0.3.16) might encounter `DeprecationWarning` related to `pkg_resources` due to changes in Python packaging.
- breaking When upgrading to NumPy 2.0+, older versions of `pandas-ta` (and potentially `ft-pandas-ta` if not on 0.3.16) may raise `ImportError: cannot import name 'NaN' from 'numpy'`. This is due to `numpy.NaN` being deprecated in favor of `numpy.nan`.
- gotcha Some indicators require specific DataFrame column names (e.g., 'open', 'high', 'low', 'close', 'volume'). If these columns are missing or incorrectly named, a `KeyError` will occur.
- breaking Pandas 3.0 introduced significant changes to copy/view semantics, deprecating `SettingWithCopyWarning` and enforcing explicit modifications. Chained assignments like `df[df['col'] > 0]['new_col'] = value` no longer work reliably. This could affect how you manipulate DataFrames with `ft-pandas-ta` results.
Install
-
pip install ft-pandas-ta
Imports
- ta
import pandas as pd import pandas_ta as ta
- DataFrame.ta
from ft_pandas_ta import ta # Then df.ta.sma()
import pandas as pd import pandas_ta as ta df = pd.DataFrame() # Your DataFrame df.ta.sma(length=10, append=True)
Quickstart
import pandas as pd
import pandas_ta as ta
import yfinance as yf # Common dependency for fetching financial data
# Fetch sample financial data
df = yf.download('AAPL', start='2022-01-01', end='2023-01-01')
# Ensure the index is a DatetimeIndex (yfinance does this by default)
# For other data sources, you might need:
# df.index = pd.to_datetime(df.index)
# Calculate a Simple Moving Average (SMA) and append to DataFrame
df.ta.sma(length=20, append=True)
# Calculate Relative Strength Index (RSI) and get it as a Series
rsi_series = df.ta.rsi(length=14)
# Calculate Bollinger Bands and append multiple columns to DataFrame
df.ta.bbands(append=True)
print(df.tail())
print(rsi_series.tail())