简体   繁体   中英

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.

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.

IIUC you can do something like this:

res = df2.rolling(9).max().eval("tenkan_sen=(High+Low)/2", inplace=False)

Result:

In [66]: res
Out[66]:
      BaseVolume     Close      High       Low      Open            TimeStamp        Volume  tenkan_sen
0            NaN       NaN       NaN       NaN       NaN  2017-12-21T22:10:00           NaN         NaN
1            NaN       NaN       NaN       NaN       NaN  2017-12-21T22:15:00           NaN         NaN
2            NaN       NaN       NaN       NaN       NaN  2017-12-21T22:20:00           NaN         NaN
3            NaN       NaN       NaN       NaN       NaN  2017-12-21T22:25:00           NaN         NaN
4            NaN       NaN       NaN       NaN       NaN  2017-12-21T22:30:00           NaN         NaN
5            NaN       NaN       NaN       NaN       NaN  2017-12-21T22:35:00           NaN         NaN
6            NaN       NaN       NaN       NaN       NaN  2017-12-21T22:40:00           NaN         NaN
7            NaN       NaN       NaN       NaN       NaN  2017-12-21T22:45:00           NaN         NaN
8      12.435173  0.001025  0.001034  0.001017  0.001034  2017-12-21T22:50:00  12186.096426    0.001026
9      12.435173  0.001025  0.001027  0.001017  0.001020  2017-12-21T22:55:00  12186.096426    0.001022
...          ...       ...       ...       ...       ...                  ...           ...         ...
5750    2.671288  0.000850  0.000850  0.000842  0.000844  2018-01-10T21:20:00   3193.127754    0.000846
5751    2.671288  0.000850  0.000850  0.000841  0.000842  2018-01-10T21:25:00   3193.127754    0.000846
5752    2.671288  0.000850  0.000850  0.000841  0.000842  2018-01-10T21:30:00   3193.127754    0.000846
5753    2.368549  0.000850  0.000850  0.000841  0.000842  2018-01-10T21:35:00   2816.322385    0.000846
5754    3.649176  0.000850  0.000850  0.000841  0.000842  2018-01-10T21:40:00   4386.363763    0.000846
5755    3.649176  0.000850  0.000850  0.000841  0.000842  2018-01-10T21:45:00   4386.363763    0.000846
5756    3.649176  0.000850  0.000850  0.000840  0.000842  2018-01-10T21:50:00   4386.363763    0.000845
5757    3.649176  0.000842  0.000842  0.000839  0.000842  2018-01-10T21:55:00   4386.363763    0.000840
5758    7.082856  0.000842  0.000842  0.000839  0.000841  2018-01-10T22:00:00   8535.312485    0.000840
5759    7.082856  0.000841  0.000842  0.000839  0.000841  2018-01-10T22:05:00   8535.312485    0.000840

[5760 rows x 8 columns]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM