Hallo zusammen,
ich bin noch recht neu mit Python unterwegs und bin leider auch recht zügig auf ein Problem gestoßen, mit dem ich gerade leider nicht alleine fertig werde. Ich versuche derzeit als Übung für meine Masterarbeit ein Arima simulation nachzubauen. Nun ist das Tutorial dazu leider schon etwas älter und der ein oder andere Weg in pandas scheint sich seither verändert zu haben. Mein Problem ist, dass in dem Tutorial die Funktion pd.rolling_mean() verwendet wird. Diese liefert als Output auch wieder den gleichen Datentyp wie der Input [type of input argument]. Nun ist es bei der aktuellen Pandas Version leider so, dass der Output nicht mehr den selben Typ hat [a Window or Rolling sub-classed for the particular operation] und ich habe es nun leider den ganzen Tag noch nicht hinbekommen mit dem Problem fertig zu werden. In Pycharm bekomme ich nur die folgende Fehlermledung : argument must be a string or a number, not 'method' welche vermutlich durch die beschriebene Änderung in Pandas entsteht. Kann mir bitte jemand sagen wie ich mein Problem lösen kann ?
Viuelen Dank im Voraus und viele Grüße
Felix
Erzeugen eines moving Avarages -> argument must be a string or a number, not 'method'
pd.rolling_mean() ist m. E. sehr veraltet - kannst du damit etwas anfangen:
https://pandas.pydata.org/pandas-docs/s ... lling.html
https://stackoverflow.com/questions/434 ... fic-column
Ohne es jetzt testen zu können:
https://pandas.pydata.org/pandas-docs/s ... lling.html
https://stackoverflow.com/questions/434 ... fic-column
Ohne es jetzt testen zu können:
Code: Alles auswählen
df['new_col'] = data['column'].rolling(5).mean()
Hey, also das war der Teil des Codes aus dem Tutorial, und die verwendete Pandas Version ist 0.23.4
from statsmodels.tsa.stattools import adfuller
def test_stationarity(timeseries):
#Determing rolling statistics
rolmean = pd.rolling_mean(timeseries, window=12)
rolstd = pd.rolling_std(timeseries, window=12)
#Plot rolling statistics:
orig = plt.plot(timeseries, color='blue',label='Original')
mean = plt.plot(rolmean, color='red', label='Rolling Mean')
std = plt.plot(rolstd, color='black', label = 'Rolling Std')
plt.legend(loc='best')
plt.title('Rolling Mean & Standard Deviation')
plt.show(block=False)
Ich habe das ganze dann versucht anzupassen und bin dann dabei gelandet, das haut aber eben auch leider nicht hin.
def test_stationarity(timeseries):
# Determing rolling statistics
rolmean = pd.DataFrame.rolling(timeseries, window=12).mean
rolstd = pd.DataFrame.rolling(timeseries, window=12).std
# Plot rolling statistics:
orig = plt.plot(ts, color='blue', label='Original')
mean = plt.plot(rolmean, color='red', label='Rolling Mean')
std = plt.plot(rolstd, color='black', label='Rolling Std')
plt.legend(loc='best')
plt.title('Rolling Mean & Standard Deviation')
plt.show(block=False)
test_stationarity(ts)
Als nächstes versuche ich es einmal mit den anmerkungen von oben.
from statsmodels.tsa.stattools import adfuller
def test_stationarity(timeseries):
#Determing rolling statistics
rolmean = pd.rolling_mean(timeseries, window=12)
rolstd = pd.rolling_std(timeseries, window=12)
#Plot rolling statistics:
orig = plt.plot(timeseries, color='blue',label='Original')
mean = plt.plot(rolmean, color='red', label='Rolling Mean')
std = plt.plot(rolstd, color='black', label = 'Rolling Std')
plt.legend(loc='best')
plt.title('Rolling Mean & Standard Deviation')
plt.show(block=False)
Ich habe das ganze dann versucht anzupassen und bin dann dabei gelandet, das haut aber eben auch leider nicht hin.
def test_stationarity(timeseries):
# Determing rolling statistics
rolmean = pd.DataFrame.rolling(timeseries, window=12).mean
rolstd = pd.DataFrame.rolling(timeseries, window=12).std
# Plot rolling statistics:
orig = plt.plot(ts, color='blue', label='Original')
mean = plt.plot(rolmean, color='red', label='Rolling Mean')
std = plt.plot(rolstd, color='black', label='Rolling Std')
plt.legend(loc='best')
plt.title('Rolling Mean & Standard Deviation')
plt.show(block=False)
test_stationarity(ts)
Als nächstes versuche ich es einmal mit den anmerkungen von oben.
- __blackjack__
- User
- Beiträge: 13922
- Registriert: Samstag 2. Juni 2018, 10:21
- Wohnort: 127.0.0.1
- Kontaktdaten:
@ff123: Sieht also so aus als wenn Du einfach nur vergessen hast die Methoden auch *aufzurufen*, und stattdessen die Methoden statt den Rückgabewert ihres Aufrufs beim Plotten übergeben hast.
“Java is a DSL to transform big Xml documents into long exception stack traces.”
— Scott Bellware
— Scott Bellware
Ok, ich habe es geschafft. Es fehlten ledigleich zwei Klammern
def test_stationarity(timeseries):
# Determing rolling statistics
rolmean = pd.DataFrame.rolling(timeseries, window=12).mean()
rolstd = pd.DataFrame.rolling(timeseries, window=12).std()
# Plot rolling statistics:
orig = plt.plot(ts, color='blue', label='Original')
mean = plt.plot(rolmean, color='red', label='Rolling Mean')
std = plt.plot(rolstd, color='black', label='Rolling Std')
plt.legend(loc='best')
plt.title('Rolling Mean & Standard Deviation')
plt.show(block=False)
test_stationarity(ts)
def test_stationarity(timeseries):
# Determing rolling statistics
rolmean = pd.DataFrame.rolling(timeseries, window=12).mean()
rolstd = pd.DataFrame.rolling(timeseries, window=12).std()
# Plot rolling statistics:
orig = plt.plot(ts, color='blue', label='Original')
mean = plt.plot(rolmean, color='red', label='Rolling Mean')
std = plt.plot(rolstd, color='black', label='Rolling Std')
plt.legend(loc='best')
plt.title('Rolling Mean & Standard Deviation')
plt.show(block=False)
test_stationarity(ts)