我是python的新手.我需要遍历给定目录的子目录并返回包含特定字符串的所有文件.
for root, dirs, files in os.walk(path):
for name in files:
if name.endswith((".sql")):
if 'gen_dts' in open(name).read():
print name
Run Code Online (Sandbox Code Playgroud)
这是我得到的最接近的.
我得到的语法错误是
Traceback (most recent call last):
File "<pyshell#77>", line 4, in <module>
if 'gen_dts' in open(name).read():
IOError: [Errno 2] No such file or directory: 'dq_offer_desc_bad_pkey_vw.sql'
Run Code Online (Sandbox Code Playgroud)
'dq_offer_desc_bad_pkey_vw.sql'文件中不包含'gen_dts'.
我提前感谢你的帮助.
我需要找到前 12 行的移动平均值。我需要让我的结果集看起来像这样。
t Year Month Sales MovingAverage
1 2010 3 20 NULL
2 2010 4 22 NULL
3 2010 5 24 NULL
4 2010 6 25 NULL
5 2010 7 23 NULL
6 2010 8 26 NULL
7 2010 9 28 NULL
8 2010 10 26 NULL
9 2010 11 29 NULL
10 2010 12 27 NULL
11 2011 1 28 NULL
12 2011 2 30 NULL
13 2011 3 27 25.67
14 2011 4 29 26.25
15 2011 …Run Code Online (Sandbox Code Playgroud) 我在R中训练了一个gbm模型.由于我试图预测一个非常罕见的情况,我得到了很多误报.我想将正("好")案例的阈值从默认值更改为0.7.到目前为止,这是我的代码.
modFit.glm.ml <- train(as.factor(ml.training$one_lease)~., data=ml.training, method = "glm")
confusionMatrix(ml.testing$one_lease, predict(modFit.glm.ml, ml.testing), positive = "Good")
Run Code Online (Sandbox Code Playgroud)
此代码有效但它使用默认截止值.有人提到这可能与预测功能,但我不知道如何做到这一点.