绘制额外的 Pandas DF

我有如下所示的代码,我试图在 7 月 - 12 月显示的绘图上为 df“ltyc”中的数据画一条黑线。我的错误是在 plt.legend 行之前的最后.


import warnings

import itertools

import numpy as np

import matplotlib.pyplot as plt

warnings.filterwarnings("ignore")

plt.style.use('fivethirtyeight')

import pandas as pd

import statsmodels.api as sm

import matplotlib


matplotlib.rcParams['axes.labelsize'] = 14

matplotlib.rcParams['xtick.labelsize'] = 12

matplotlib.rcParams['ytick.labelsize'] = 12

matplotlib.rcParams['text.color'] = 'k'

from sys import exit


df = pd.read_excel("MOSDailyWindSpeed.xlsx")


wspdBH1 = df.groupby('Date')[' Simulated WS BH1PI'].sum().reset_index()

wspdHOO = df.groupby('Date')[' Simulated WS HOO801'].sum().reset_index()

wspdBH1 = wspdBH1.set_index('Date')

wspdHOO = wspdHOO.set_index('Date')

wspdBH1.index

wspdHOO.index

y = wspdHOO[' Simulated WS HOO801'].resample('MS').mean()#monthly mean --> 

change site here 'MS' is month start for 'Date' col

y['2017':]#look at daily data starting 2017 -view data 


y.plot(figsize=(15, 6))

plt.show()


from pylab import rcParams

rcParams['figure.figsize'] = 18, 8


decomposition = sm.tsa.seasonal_decompose(y, model='additive')

fig = decomposition.plot()

plt.show()


p = d = q = range(0, 2)

pdq = list(itertools.product(p, d, q))

seasonal_pdq = [(x[0], x[1], x[2], 12) for x in list(itertools.product(p, 

d, q))]


print('Examples of parameter combinations for Seasonal ARIMA...')

print('SARIMAX: {} x {}'.format(pdq[1], seasonal_pdq[1]))

print('SARIMAX: {} x {}'.format(pdq[1], seasonal_pdq[2]))

print('SARIMAX: {} x {}'.format(pdq[2], seasonal_pdq[3]))

print('SARIMAX: {} x {}'.format(pdq[2], seasonal_pdq[4]))


for param in pdq:

  for param_seasonal in seasonal_pdq:

    try:

        mod = sm.tsa.statespace.SARIMAX(y,

                                        order=param,

                                        seasonal_order=param_seasonal,

                                        enforce_stationarity=False,

                                        enforce_invertibility=False)

http://img.mukewang.com/6408523d00010e3206550337.jpg

大话西游666
浏览 92回答 1
1回答

holdtom

我用它来将整数日期转换为 DF 中的 yyyy-mm-dd 格式。ltyc['Date'] = pd.to_datetime(ltyc["Date"], format='%m').apply(lambda dt: dt.replace(year=2020))然后,我将 DF (ltyc) 转换成这样的系列: ltycs = pd.Series(ltyc['LT Mean'].values, index=ltyc['Date'])#convert to Series 因为其他图都在系列格式ltycs.plot(label='LT Mean',ax=ax,color='k')
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python