小编lin*_*gta的帖子

argparse添加示例用法

我使用argparse来处理输入参数,并使用parser.print_help()输出以下内容:

optional arguments:
  -h, --help            show this help message and exit
  -t TEMPLATES, --templates TEMPLATES
                    template names to make, should be defined as section
                    name in conf, and have related file in templates/
                    folder
  -c CONFPATH, --confpath CONFPATH
                    configuration path for template detail info
Run Code Online (Sandbox Code Playgroud)

我的代码如下所示:

    import argparse
    parser = argparse.ArgumentParser(prog='base_maker', description='template maker')
    parser.add_argument('-t', '--templates', help='template names to make, should be defined as section name in conf, and have related file in templates/ folder', type=str)
    parser.add_argument('-c', '--confpath', help='configuration path for template …
Run Code Online (Sandbox Code Playgroud)

python argparse

11
推荐指数
1
解决办法
4718
查看次数

守护进程不允许有子进程

我知道这是一个常见的问题,像相关的问题这样,但我要问,以适合我的情况,因为我还没有现在用芹菜最好的办法.

我的服务方案将使用multiprocessing.Process创建多个广告系列订单,在每个广告系列订单中,它仍然使用multiprocessing.Process来创建多个广告(广告系列和广告是1toM关系).

如你所知,如果我设置两个广告系列和广告制作部分多进程,它将失败,"恶魔的过程中是不允许生孩子",我觉得芹菜可满足即使我现在不使用它类似的问题.

我的问题是,解决这类问题的一般方法是什么?我应该使用芹菜还是以任何方式解决它?

非常感谢

python daemon multiprocessing

9
推荐指数
1
解决办法
2814
查看次数

熊猫 - 应用函数缓慢的解释

对于大型数据帧(大约1~3百万行),应用函数似乎工作得非常慢.

我在这里检查了相关的问题,比如加速熊猫应用功能,以及在pandas apply()函数中计数,似乎加速它的最好方法是不使用apply函数:)

对于我的情况,我有两种与apply函数有关的任务.

第一:应用查找字典查询

f(p_id, p_dict):
    return p_dict[p_dict['ID'] == p_id]['value']

p_dict = DataFrame(...)  # it's another dict works like lookup table
df = df.apply(f, args=(p_dict,))
Run Code Online (Sandbox Code Playgroud)

第二:适用于groupby

f(week_id, min_week_num, p_dict):
    return p_dict[(week_id - min_week_num < p_dict['WEEK']) & (p_dict['WEEK'] < week_id)].ix[:,2].mean()

f_partial = partial(f, min_week_num=min_week_num, p_dict=p_dict)
df = map(f, df['WEEK'])
Run Code Online (Sandbox Code Playgroud)

我想对于第一种情况,它可以通过数据帧连接完成,而我不确定这种连接在大型数据集上的资源成本.

我的问题是:

  1. 在上述两种情况下,有没有办法替代申请?
  2. 为什么这么慢?对于dict查找案例,我认为它应该是O(N),即使N是100万,也不应该花费那么多.

python pandas

6
推荐指数
1
解决办法
9654
查看次数

一键编码用于决策树后如何解释特征重要性

我知道决策树具有由Gini计算的feature_importance属性,它可用于检查哪些功能更重要。

但是,对于scikit-learn或Spark中的应用程序,它仅接受数字属性,因此我必须将字符串属性转换为数字属性,然后对此进行一键编码。将特征放入决策树模型时,它是原始编码以外的0-1编码,我的问题是,如何解释特征对原始属性的重要性?试图解释功能重要性时,应避免使用单编码器吗?

谢谢。

machine-learning decision-tree scikit-learn

6
推荐指数
1
解决办法
1583
查看次数