pythonpandasdataframerolling-computationfuture-warning

Pandas Dataframe rolling_max futurewarning error


i have a python pandas code to parse url Json data from api to dataframe

import pandas as pd
import json
import urllib.request
import os
from pandas import DataFrame

    with urllib.request.urlopen(
                            "https://bittrex.com/Api/v2.0/pub/market/GetTicks?marketName=BTC-WAVES&tickInterval=fiveMin") as URL:
        data = json.loads(URL.read().decode())
        df2 = pd.DataFrame(data=data['result'])
        df2.rename(columns={'BV': 'BaseVolume', 'C': 'Close', 'H': 'High', 'L': 'Low', 'O': 'Open', 'T': 'TimeStamp','V': 'Volume'}, inplace=True)

    high_prices = df2['High']
    close_prices = df2['Close']
    low_prices = df2['Low']
    TimeStamp = df2.index
    nine_period_high = pd.rolling_max(df2['High'], window=9)
    nine_period_low = pd.rolling_min(df2['Low'], window=9)
    df2['tenkan_sen'] = (nine_period_high + nine_period_low) /2

    # Kijun-sen (Base Line): (26-period high + 26-period low)/2))
    period26_high = pd.rolling_max(high_prices, window=26)
    period26_low = pd.rolling_min(low_prices, window=26)
    df2['kijun_sen'] = (period26_high + period26_low) / 2

    # Senkou Span A (Leading Span A): (Conversion Line + Base Line)/2))
    df2['senkou_span_a'] = ((df2['tenkan_sen'] + df2['kijun_sen']) / 2).shift(26)

    # Senkou Span B (Leading Span B): (52-period high + 52-period low)/2))
    period52_high = pd.rolling_max(high_prices, window=52)
    period52_low = pd.rolling_min(low_prices, window=52)
    df2['senkou_span_b'] = ((period52_high + period52_low) / 2).shift(26)

print('df2')
print('DONE')

it works perfect to me except this error (Not: it doesn't effect result, but i am worry from this future warning.

FutureWarning: pd.rolling_max is deprecated for Series and will be removed in a future version, replace with 
    Series.rolling(window=9,center=False).max()
  nine_period_high = pd.rolling_max(df2['High'], window=9)

and the same error always repeated with all rolling_max and rolling_min in all script.

any body can help please.


Solution

  • Change the pd.rolling_max() method calls to .rolling().max() etc etc

    Same for mins.

    pd.rolling_max(df2['High'], window=9)
    

    becomes

    df2['High'].rolling(window=9).max()
    

    The deprecation warning suggests exactly this, that the rolling_min and rolling_max functions will not be supported in future versions of pandas.