Python 熊猫数据帧滚动最大未来警告错误
我有一个python代码来将url Json数据从api解析到dataframePython 熊猫数据帧滚动最大未来警告错误,python,pandas,dataframe,rolling-computation,future-warning,Python,Pandas,Dataframe,Rolling Computation,Future Warning,我有一个python代码来将url Json数据从api解析到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?mark
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)
在所有脚本中的所有滚动最大值和滚动最小值都会重复相同的错误
任何人都可以帮忙。将pd.rolling\u max()方法调用更改为.rolling().max()等
分钟也一样
pd.rolling_max(df2['High'], window=9)
变成
df2['High'].rolling(window=9).max()
弃用警告正好表明,未来版本的pandas将不支持rolling_min和rolling_max功能。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]
您是否尝试按照Pandas的警告进行操作?是的,但出现以下错误类型错误:rolling()缺少1个必需的位置参数:“self”感谢您的重播,我出现了此错误(AttributeError:module'Pandas'没有属性“rolling”)。您应该调用该系列,而不是Pandas本身,因此
df2['High']。rolling(window=9).max()
@PatrickO'Connor现在它工作得很好..非常感谢各位兄弟我最好使用一行命令,但不幸的是它对我不起作用,我得到了一个关键错误:“tenkan_sen”…我尝试了df2[tenkan_sen]=df2.rolling(9).max().eval(“tenkan_sen=(高+低)/2”,inplace=False)但不起作用..还尝试用True替换False,但也有错误..如果您能提供另一种格式..我将很高兴