草庐IT

rolling_mean

全部标签

python - Pandas 滚动窗口和日期时间索引 : What does `offset` mean?

滚动窗口函数pandas.DataFrame.rollingpandas0.22的window参数如下所述:window:int,oroffsetSizeofthemovingwindow.Thisisthenumberofobservationsusedforcalculatingthestatistic.Eachwindowwillbeafixedsize.Ifitsanoffsetthenthiswillbethetimeperiodofeachwindow.Eachwindowwillbeavariablesizedbasedontheobservationsincludedi

python Pandas : mean and sum groupby on different columns at the same time

我有一个pandas数据框,如下所示:NameMissedCreditGradeA1310A1112B2310B1220我想要的输出是:NameSum1Sum2AverageA2411B3515基本上是获取列Credit和Missed的总和,并在Grade上取平均值。我现在正在做的是Name上的两个groupby,然后求和和平均值,最后合并两个输出数据帧,这似乎不是最好的方法。我还在SO上发现了这一点,如果我只想在一列上工作,这很有意义:df.groupby('Name')['Credit'].agg(['sum','average'])但不确定如何为两列做一行?

Python 统计模型 : Using SARIMAX with exogenous regressors to get predicted mean and confidence intervals

我正在使用statsmodels.tsa.SARIMAX()来训练具有外生变量的模型。当使用外生变量训练模型以便返回的对象包含预测均值和置信区间而不仅仅是一组预测均值结果时,是否存在get_prediction()的等价物?predict()和forecast()方法采用外生变量,但只返回预测平均值。SARIMA_model=sm.tsa.SARIMAX(endog=y_train.astype('float64'),exog=ExogenousFeature_train.values.astype('float64'),order=(1,0,0),seasonal_order=(2,

python 2 : different meaning of the 'in' keyword for sets and lists

考虑这个片段:classSomeClass(object):def__init__(self,someattribute="somevalue"):self.someattribute=someattributedef__eq__(self,other):returnself.someattribute==other.someattributedef__ne__(self,other):returnnotself.__eq__(other)list_of_objects=[SomeClass()]print(SomeClass()inlist_of_objects)set_of_obj

python - 如何使用 Python 从最高到最低设置 k-Means 聚类标签?

我有一个包含38间公寓及其早上、下午和晚上的用电量的数据集。我正在尝试使用scikit-learn中的k-Means实现对该数据集进行聚类,并得到了一些有趣的结果。第一个聚类结果:一切都很好,对于4个集群,我显然得到了与每个公寓关联的4个标签-0、1、2和3。使用KMeans的random_state参数>方法,我可以修复其中随机初始化质心的种子,因此我始终如一地获得归因于相同公寓的相同标签。但是,由于此特定案例涉及能源消耗,因此可以在最高和最低消费者之间执行可衡量的分类。因此,我想将标签0分配给消费水平最低的公寓,将标签1分配给消费多一点的公寓,依此类推。截至目前,我的标签是[213

python - 使用 Scikit Learn K-Means 大放异彩

我正在尝试使Blaze数据对象适合scikitkmeans函数。fromblazeimport*fromsklearn.clusterimportKMeansdata_numeric=Data('data.csv')data_cluster=KMeans(n_clusters=5)data_cluster.fit(data_numeric)数据样本:ABC1323455792896721它的抛出错误:我已经能够使用PandasDataframe做到这一点。有什么方法可以将blaze对象提供给此函数? 最佳答案 我认为您需要在适合之前

python - aiohttp+sqlalchemy : Can't reconnect until invalid transaction is rolled back

我正在使用aiohttp和sqlalchemy,并且我创建了一个Singleton,它可以在我需要SQLAlchemy实例时帮助我连接(代码如下).不幸的是,每隔一段时间我就会收到以下错误(我通过重新启动服务器来“解决”):Dec1109:35:29ip-xxx-xxx-xxx-xxxgunicorn[16513]:sqlalchemy.exc.StatementError:(sqlalchemy.exc.InvalidRequestError)Can'treconnectuntilinvalidtransactionisrolledback[SQL:'...\nFROM...\nWH

python - 在 DataFrame 对象上使用 rolling_apply

我正在尝试滚动计算成交量加权平均价格。为此,我有一个函数vwap可以为我执行此操作,如下所示:defvwap(bars):return((bars.Close*bars.Volume).sum()/bars.Volume.sum()).round(2)当我尝试将此函数与rolling_apply一起使用时,如图所示,出现错误:importpandas.io.dataaswebbars=web.DataReader('AAPL','yahoo')printpandas.rolling_apply(bars,30,vwap)AttributeError:'numpy.ndarray'obj

python - 错误: `Loaded runtime CuDNN library: 5005 but source was compiled with 5103` mean?是什么意思

我试图将TensorFlow与GPU结合使用,但出现以下错误:Itensorflow/core/common_runtime/gpu/gpu_device.cc:838]CreatingTensorFlowdevice(/gpu:0)->(device:0,name:TeslaK20m,pcibusid:0000:02:00.0)Etensorflow/stream_executor/cuda/cuda_dnn.cc:347]LoadedruntimeCuDNNlibrary:5005(compatibilityversion5000)butsourcewascompiledwith5

python - 如何使用谷歌的 "did you mean?"实现 python 拼写检查器

我正在寻找一种在python中创建函数的方法,您可以在其中传入字符串并返回是否拼写正确。我不想查字典。相反,我希望它检查谷歌的拼写建议。这样,名人姓名和其他各种专有名词都算作拼写正确。这是我目前所处的位置。它大部分时间都有效,但它会混淆一些名人的名字。例如,“ceelogreen”或“posner”之类的内容会被标记为不正确。importhttplibimportxml.dom.minidomdata="""%s"""defspellCheck(word_to_spell):con=httplib.HTTPSConnection("www.google.com")con.request