小编ari*_*ell的帖子

使用pandas中的多个值从列创建虚拟对象

我正在寻找一种pythonic方式来处理以下问题.

The pandas.get_dummies() method is great to create dummies from a categorical column of a dataframe. For example, if the column has values in ['A', 'B'], get_dummies() creates 2 dummy variables and assigns 0 or 1 accordingly.

Now, I need to handle this situation. A single column, let's call it 'label', has values like ['A', 'B', 'C', 'D', 'A*C', 'C*D'] . get_dummies() creates 6 dummies, but I only want 4 of them, so that a row could have multiple …

python dummy-data pandas categorical-data

30
推荐指数
2
解决办法
2万
查看次数

ALTER角色与CREATEDB和GRANT CREATE在TABLESPACE之间的区别

来自MySQL而不知道ROLE我心不在焉地试了这个

GRANT CREATE ON TABLESPACE pg_default TO username;
Run Code Online (Sandbox Code Playgroud)

它没有达到预期的效果.我正在寻找的命令是:

ALTER ROLE username WITH CREATEDB;
Run Code Online (Sandbox Code Playgroud)

但究竟有什么不同呢?给某人CREATEDB角色隐含地给他们CREATE ON TABLESPACE ...?有桌子我可以看到这一切吗?

文档中,GRANT CREATE ON TABLESPACE意味着(我的重点):

对于表空间,允许在表空间中创建表,索引和临时文件,并 允许创建将表空间作为其默认表空间的数据库.(请注意,撤消此权限不会改变现有对象的位置.)

postgresql

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

泡菜cython类

我必须保存并加载一个cython类实例.我的cython类是以及几种方法:

import numpy as np
cimport numpy as np
cimport cython    
cdef class Perceptron_avg_my:
    cdef int wlen,freePos
    cdef np.ndarray w,wtot,wac,wtotc #np.ndarray[np.int32_t]
    cdef np.ndarray wmean  #np.ndarray[np.float32_t]    
    cdef public dict fpos    

    def __cinit__(self,np.int64_t wlen=4*10**7):
        self.fpos= dict()
        self.freePos=1
        self.wlen=wlen
        self.w=np.zeros(wlen,np.int32)
        self.wtot=np.zeros(wlen,np.int32)
        self.wac=np.zeros(wlen,np.int32)
        self.wtotc=np.zeros(wlen,np.int32)
        self.wmean=np.zeros(wlen,np.float32)

    cpdef evaluate_noavg(self,list f):
        cdef np.ndarray[np.int32_t] w = self.w
        cdef dict fpos = self.fpos        
        cdef bytes ff
        cdef int i
        cdef long int score=0

        for ff in f:
            i=fpos.get(ff,0)  
            if i != 0: 
                score += w[i]
        return score
Run Code Online (Sandbox Code Playgroud)

我在考虑使用cPickle模块.我明白我必须实现一个__reduce __(自我)方法但是我有一些问题需要找到一个例子并且很好地理解文档 …

python reduce class pickle cython

9
推荐指数
2
解决办法
7396
查看次数

重新排序数据框列,同时忽略未识别的列

我认为必须有一个更好的方法来做到这一点.

我正在尝试重新排序数据框中的列.我有一个列表,ordered.colnames代表了新的排序-但一些列不存在dataset.为了避免错误" undefined columns selected",我将相关切片包装在一个try()函数中.

以下方法有效,但是有更好的方法吗?

> ordered.colnames[1:5]
[1] "lady_22102"         "attentions_83249"   "perseverance_17864"
[4] "cecil_84477"        "cecilia_133476"

dataset.reordered = c() 
for (i in 1:length(ordered.colnames)) {
    col = NA
    col = try(cbind(dataset[,ordered.colnames[i]]),silent=TRUE)
    if (!inherits(col,"try-error")) {
        colnames(col) = ordered.colnames[i]
        dataset.reordered = cbind(dataset.reordered, col) 
    }
}
Run Code Online (Sandbox Code Playgroud)

r dataframe

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

为什么 concurrent.futures 不制作参数的副本?

我的理解是 concurrent.futures 依靠酸洗参数来让它们在不同的进程(或线程)中运行。酸洗不应该创建参数的副本吗?在 Linux 上它似乎没有这样做,即,我必须明确地传递一个副本。

我试图理解以下结果:

<0> rands before submission: [17, 72, 97, 8, 32, 15, 63, 97, 57, 60]
<1> rands before submission: [97, 15, 97, 32, 60, 17, 57, 72, 8, 63]
<2> rands before submission: [15, 57, 63, 17, 97, 97, 8, 32, 60, 72]
<3> rands before submission: [32, 97, 63, 72, 17, 57, 97, 8, 15, 60]
in function 0 [97, 15, 97, 32, 60, 17, 57, 72, 8, 63]
in function 1 [97, 32, …
Run Code Online (Sandbox Code Playgroud)

python parallel-processing multiprocessing python-3.x concurrent.futures

5
推荐指数
1
解决办法
1817
查看次数

使用历史数据样本估计未来的增长

我有过去几年数据库增长(就规模而言)的历史记录。我试图找出可以根据历史记录向我展示数据库未来增长的最佳方式/图表,当然,如果我们添加一个新表并且它也会增长,这将无济于事,但我只是在寻找一种估计它的方法。我对 Python 或 R 的想法持开放态度

以下是多年来以 TB 为单位的数据库大小:


3.895 - 2012 6.863 - 2013
8.997 - 2014
10.626 - 2015

python r approximation

1
推荐指数
2
解决办法
1436
查看次数