假设我们有一个时间序列数据,其中包含最近两年的每日订单计数:

我们可以使用Python的statsmodels库来预测未来的订单:
fit = statsmodels.api.tsa.statespace.SARIMAX(
train.Count, order=(2, 1, 4),seasonal_order=(0,1,1,7)
).fit()
y_hat_avg['SARIMA'] = fit1.predict(
start="2018-06-16", end="2018-08-14", dynamic=True
)
Run Code Online (Sandbox Code Playgroud)
结果(不介意数字):
现在假设由于公司假期或促销活动,我们的输入数据有一些异常的增加或减少。因此,我们添加了两列,分别说明每天是否是“假期”以及公司是否有“促销”。
是否有一种方法(以及在Python中实现它的方法)使用这种新型的输入数据,并帮助该模型理解异常值的原因,并通过提供“假期”和“ promotion_day”信息来预测未来的订单?
fit1.predict('2018-08-29', holiday=True, is_promotion=False)
# or
fit1.predict(start="2018-08-20", end="2018-08-25", holiday=[0,0,0,1,1,0], is_promotion=[0,0,1,1,0,1])
Run Code Online (Sandbox Code Playgroud) 假设我们有一个 pyspark 数据框,其中一列 ( column_a) 包含一些字符串值,并且还有一个字符串列表 ( list_a)。
数据框:
column_a | count
some_string | 10
another_one | 20
third_string | 30
Run Code Online (Sandbox Code Playgroud)
列表_a:
['string', 'third', ...]
Run Code Online (Sandbox Code Playgroud)
如果 column_a 的值包含 list_a 的项目之一,我想过滤此数据框并仅保留行。
这是用于column_a基于单个字符串过滤的代码:
df['column_a'].like('%string_value%')
Run Code Online (Sandbox Code Playgroud)
但是,对于字符串列表,我们如何获得相同的结果呢?(保留 column_a 的值为 'string'、'third' 的行,...)
我想在 FastAPI 中实现支持部分更新的 put 或 patch 请求。官方文档真的很混乱,我不知道如何执行请求。(我不知道items文档中是否有此内容,因为我的数据将与请求的正文一起传递,而不是硬编码的字典)。
class QuestionSchema(BaseModel):
title: str = Field(..., min_length=3, max_length=50)
answer_true: str = Field(..., min_length=3, max_length=50)
answer_false: List[str] = Field(..., min_length=3, max_length=50)
category_id: int
class QuestionDB(QuestionSchema):
id: int
async def put(id: int, payload: QuestionSchema):
query = (
questions
.update()
.where(id == questions.c.id)
.values(**payload)
.returning(questions.c.id)
)
return await database.execute(query=query)
@router.put("/{id}/", response_model=QuestionDB)
async def update_question(payload: QuestionSchema, id: int = Path(..., gt=0),):
question = await crud.get(id)
if not question:
raise HTTPException(status_code=404, detail="question not found") …Run Code Online (Sandbox Code Playgroud) 我有一个瀑布图,我想分别设置每个条形的颜色(第一个为蓝色,第二个、第三个和第四个为红色,第五个为绿色,第六个为蓝色)。图表中所有的相关条都是递增的,而plotly只允许你设置递增、递减和总计三种颜色。有什么办法可以做我想做的事吗?
import plotly.graph_objects as go
fig = go.Figure(go.Waterfall(
name = "20", orientation = "v",
measure = ["relative", "relative", "relative", "relative", "relative", "total"],
x = ["Buy", "Transaction Cost", "Remodeling Cost", "Ownership Cost", "Gain", "Sell"],
textposition = "outside",
text = ["$200", "$14", "$45", "$5", "$86", "$350"],
y = [200, 14, 45, 5, 86, 350],
connector = {"visible": False}
))
fig.show()
Run Code Online (Sandbox Code Playgroud)
正如我所说,我希望条形图的颜色是:
blue for the first one, red for the 2nd, 3rd, and 4th one, green for 5th one, and blue for …
我有两个数据框。数据框 A 有一个由listids(命名项)值组成的列。数据框 B 有一列intids 值(名为 id)。
数据框A:
date | items
2019-06-05 | [121, 123, 124]
2019-06-06 | [109, 125]
2019-06-07 | [108, 126]
Run Code Online (Sandbox Code Playgroud)
数据框B:
name | id
item1 | 121
item2 | 122
item3 | 123
item4 | 124
item5 | 125
item6 | 126
Run Code Online (Sandbox Code Playgroud)
我想过滤 Dataframe A 并仅保留items该行中所有值都存在于idDataframe B 列中的行。
根据上面的例子,结果应该是:
数据框C:
date | items
2019-06-05 | [121, 123, 124]
Run Code Online (Sandbox Code Playgroud)
(因为数据框 B 没有 id==108 和 id==109 的行)
如果items是一 …
我已经使用本教程部署了我的 Django 项目,并且运行良好。
现在我想拆分设置文件并在开发和生产环境中有多个设置。我创建了一个settings目录并将这些文件添加到目录中:
my_project/
manage.py
my_project/
__init__.py
urls.py
wsgi.py
settings/
__init__.py
base.py
dev.py
prod.py
Run Code Online (Sandbox Code Playgroud)
本base.py是同前settings.py(即是工作的罚款)。我导入base.py并添加了DEBAG=False和ALLOWED_HOSTS到prod.py.
如何告诉 gunicorn 使用prod设置运行我的应用程序?
该gunicorn.service文件,基于教程是这样的:
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/sammy/myproject
ExecStart=/home/sammy/myproject/myprojectenv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/sammy/myproject/myproject.sock myproject.wsgi:application
[Install]
WantedBy=multi-user.target
Run Code Online (Sandbox Code Playgroud) python ×5
python-3.x ×2
django ×1
fastapi ×1
gunicorn ×1
pandas ×1
plotly ×1
pydantic ×1
pyspark ×1
sqlalchemy ×1
statsmodels ×1
time-series ×1