小编Fed*_*ato的帖子

Python:如何在 2020 年提供单个可执行文件而不显示代码

Stack Overflow 有很多关于

  • 如何给别人一个保护源代码的python脚本
  • 如何编译python文件
  • 如何创建包和部署代码

但我找不到我的问题的答案:

我想给别人我的python脚本,而不给他源代码。我目前的尝试是编译文件并赠送 .pyc 文件。

这肯定不是最好的解决方案。此外,我的代码是由不同的文件制作的。为了提供单个可执行的 pyc 文件,我在编译之前将所有代码放在一个文件中:对开发人员来说真是地狱

我怎样才能以更干净的方式实现我的目标?

旁注

我知道 .pyc 文件不会隐藏太多,但与提供 .py 文件相比,它肯定更好

尽管如此,.pyc 文件可能会出现令人难以置信的问题(因为它们可能依赖于系统)

python deployment

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

Pandas Timedelta 平均值返回错误“没有要聚合的数字类型”。为什么?

我正在尝试执行以下操作:

pd.concat([A,B], axis = 1).groupby("status_reason")["closing_time"].mean()
Run Code Online (Sandbox Code Playgroud)

在哪里

  • A 是一个名为“status_reason”的系列(分类值)
  • B 是一个名为“close_time”的系列(TimeDelta 值)

例子:

In : A.head(5)
Out: 
     0    -1 days +11:35:00
     1   -10 days +07:13:00
     2                  NaT
     3                  NaT
     4                  NaT
    Name: closing_time, dtype: timedelta64[ns]

In : B.head(5)
Out:
     0            Won
     1       Canceled
     2    In Progress
     3    In Progress
     4    In Progress
     Name: status_reason, dtype: object
Run Code Online (Sandbox Code Playgroud)

出现以下错误:

DataError: No numeric types to aggregate
Run Code Online (Sandbox Code Playgroud)

请注意:我尝试执行平均值,甚至隔离每个类别

现在,我在网上看到了一些与我类似的问题,所以我尝试了以下方法:

pd.to_timedelta(pd.concat([pd.to_numeric(A),B], axis = 1).groupby("status_reason")["closing_time"].mean())
Run Code Online (Sandbox Code Playgroud)

这只是将 Timedelta 转换为 int64,反之亦然。但结果很奇怪(数字太高)

为了排查情况,我编写了如下代码:

xxx = pd.concat([A,B], axis = 1)
xxx.closing_time.mean() …
Run Code Online (Sandbox Code Playgroud)

python type-conversion timedelta pandas

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

Scikit 管道参数 - fit() 得到了一个意外的关键字参数“gamma”

包括最小可行示例;)

我想要的只是使用来自 GridSearchCV 的参数来使用 Pipeline

#I want to create a SVM using a Pipeline, and validate the model (measure the accuracy)
#import libraries
from sklearn.svm import SVC
from sklearn.model_selection import GridSearchCV
from sklearn.preprocessing import StandardScaler
from sklearn.pipeline import Pipeline
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
import pandas as pd

#load test data
data = load_iris()
X_trainset, X_testset, y_trainset, y_testset = train_test_split(data['data'], data['target'], test_size=0.2)

#And here we prepare the pipeline
pipeline = Pipeline([('scaler', StandardScaler()), ('SVM', SVC())])
grid …
Run Code Online (Sandbox Code Playgroud)

python pipeline machine-learning scikit-learn grid-search

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

如何使 Bootstrap 网格列填充整个剩余行?

我收到一些元素,并且想在页面中插入一些元素。这些元素可以是“小”或“大”。我无法提前知道我将收到多少元素或它们的顺序。

  • 如果它们是“小”,我希望它们是大的col-4
  • 如果它们“大”,我希望它们从前一个元素到行尾尽可能大。

因此,“大”元素可以很大col-4col-8或者col-12取决于它的位置。在一张图片中:

在此输入图像描述

我在 SO 上发现的最相似的问题如下:Bootstrap fill left columns

我尝试使用问题中建议的方法,但它不涵盖在同一行中“大”元素后面有一个“小”元素的情况。使用链接问题中的相同词语:

它不包括在同一行中,流氓元素后面有一个蓝色元素的情况

.col-4{
  background:red;
}

.big{
 background:yellow; 
}

.row{
  background:white;
}

 
Run Code Online (Sandbox Code Playgroud)
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.0/dist/css/bootstrap.min.css" rel="stylesheet"/>

<h1>
Expected result
</h1>
The goal is to obtain this same behaviour using the same style for every "big" element

<div class="container-fluid pt-2">
  <div class="row">
    <div class="col-4 mb-1">
      small
    </div>
    <div class="col-4  mb-1">
      small
    </div>
    <div class="col-4  mb-1">
      small
    </div>
    <div class="col-12 big mb-1">
      big …
Run Code Online (Sandbox Code Playgroud)

html css twitter-bootstrap bootstrap-5

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