Pandas 数据框 rolling_max 未来警告错误
Pandas Dataframe rolling_max futurewarning error
我有一个 python pandas 代码来解析 url Json 数据从 api 到数据帧
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')
它对我来说很完美,除了这个错误(不是:它不会影响结果,但我担心未来的警告。
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)
并且所有脚本中的所有 rolling_max 和 rolling_min 总是重复相同的错误。
任何人都可以提供帮助。
将 pd.rolling_max() 方法调用更改为 .rolling().max() 等
分钟相同。
pd.rolling_max(df2['High'], window=9)
变成
df2['High'].rolling(window=9).max()
弃用警告表明,rolling_min 和 rolling_max 函数在 pandas 的未来版本中将不被支持。
IIUC 你可以这样做:
res = df2.rolling(9).max().eval("tenkan_sen=(High+Low)/2", inplace=False)
结果:
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]
我有一个 python pandas 代码来解析 url Json 数据从 api 到数据帧
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')
它对我来说很完美,除了这个错误(不是:它不会影响结果,但我担心未来的警告。
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)
并且所有脚本中的所有 rolling_max 和 rolling_min 总是重复相同的错误。
任何人都可以提供帮助。
将 pd.rolling_max() 方法调用更改为 .rolling().max() 等
分钟相同。
pd.rolling_max(df2['High'], window=9)
变成
df2['High'].rolling(window=9).max()
弃用警告表明,rolling_min 和 rolling_max 函数在 pandas 的未来版本中将不被支持。
IIUC 你可以这样做:
res = df2.rolling(9).max().eval("tenkan_sen=(High+Low)/2", inplace=False)
结果:
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]