专栏名称: python
隔天更新python文章,我希望用我的努力换来劳动的成果帮助更多的人掌握一门技术,因此我要更加努力。
目录
相关文章推荐
51好读  ›  专栏  ›  python

一切尽在掌控之中:这个Python脚本,让工作自动向你汇报进度

python  · 公众号  · Python  · 2021-05-08 21:35

正文

请到「今天看啥」查看全文


{MODELNAME}/epoch_{e}_loss.png ,
f .. /visuals/ {MODELNAME}/epoch_{e}_iter_{i}.png
]
) # note that weattach two images here, the loss plot and
# ...a generated image output from our model
notify.send(msg) # we then send the message

每隔100个epoch,就会发送一封包含上述所有内容的电子邮件。以下是其中一封邮件:



数据处理和传输

这点不是很有趣,但在时间消耗方面,它排第一名。

以使用Python将批量数据上传到SQLServer为例(对于没有BULK INSERT的人)。在上传脚本的最后,会有一个简单的消息通知上传完成。

import os
import notify
from data importSql # seehttps://jamescalam.github.io/pysqlplus/lib/data/sql.html
dt =Sql( database123 , server001 ) # setup theconnection to SQL Server
for i, file inenumerate(os.listdir( ../data/new )):
dt.push_raw(f ../data/new/{file} ) # push a file to SQL Server
# once the upload is complete, send a notification
# first we create the message
msg = notify.message(
subject= SQL Data Upload ,
text=f Data upload complete, {i} filesuploaded. ,
)
# send the message
notify.send(msg)

如果偶尔抛出错误,还可以添加一个try-except语句来捕获错误,并将其添加到一个列表中,以包含在更新和/或完成电子邮件中。


金融模型

金融建模中运行的所有东西实际上都非常快,所以此处只能提供一个示例。

以 现金流动模型工具 为例。现实中,这个过程只需要10-20秒,但现在假设你是华尔街炙手可热的定量分析师,正在处理几百万笔贷款。在这封电子邮件中,可能想要包含一个高级概要分析的投资组合。可以随机选择一些贷款,并在给定的时间段内可视化关键值——给定一个小样本来交叉检验模型的性能。

end = datetime.datetime.now()  # get the ending datetime
# get the total runtime in hours:minutes:seconds
hours,rem =divmod((end - start).seconds, 3600)
mins,secs =divmod(rem, 60)
runtime= {:02d}:{:02d}:{:02






请到「今天看啥」查看全文