小编Ale*_*lli的帖子

Streamlit 超时:您的应用程序在加载组件时遇到问题

我正在尝试显示 Streamlit/Hydralit 组件,但是当我将其部署到 Cloud Run 上时,我遇到了此超时错误(本地从未遇到过):

Your app is having trouble loading the hydralit_components.NavBar.nav_bar component.

(The app is attempting to load the component from **, and hasn't received its "streamlit:componentReady"** message.)

If this is a development build, have you started the dev server?
If this is a release build, have you compiled the frontend?
For more troubleshooting help, please see the Streamlit Component docs or visit our forums.
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

我该如何解决这个相关问题?

streamlit

8
推荐指数
1
解决办法
2700
查看次数

pd.to_datetime小时和秒

晚上好,

我有一个dataframe(Pandas),其列表示日期,格式如下:

print(df["date"])

14/01/18 12:47
14/01/18 12:48
14/01/18 12:50
14/01/18 12:57
14/01/18 12:57
14/01/18 12:57
14/01/18 12:57
14/01/18 12:57
14/01/18 12:58
Run Code Online (Sandbox Code Playgroud)

具体来说,我想:1. 使用pd.to_datetime 转换datetime。2 .创建以下附加

df["month"]
df["day"]
df["year"]
df["hour"]
df["minute"]
Run Code Online (Sandbox Code Playgroud)

我试着跑:

df['date'] = pd.to_datetime(df['date'], format = "%d/%m/%Y %H/%M" )
Run Code Online (Sandbox Code Playgroud)

但是出现以下错误

time data '02/01/18 08:41' does not match format '%d/%m/%Y %H/%M' (match)
Run Code Online (Sandbox Code Playgroud)

python datetime

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

XGBoost 最佳迭代

我正在使用 XGBoost 算法进行回归,因为

clf = XGBRegressor(eval_set = [(X_train, y_train), (X_val, y_val)],
                       early_stopping_rounds = 10, 
                       n_estimators = 10,                    
                       verbose = 50)

clf.fit(X_train, y_train, verbose=False)
print("Best Iteration: {}".format(clf.booster().best_iteration))
Run Code Online (Sandbox Code Playgroud)

它正确地训练自己,但打印功能引发以下错误,

TypeError: 'str' object is not callable
Run Code Online (Sandbox Code Playgroud)

如何获得模型的最佳 迭代次数

此外,我怎么能打印训练 误差 一轮

regression machine-learning python-3.x xgboost

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

预测循环的剩余时间

晚上好,

我试图估计循环结束的剩余 时间我用过:

start = datetime.now()
progress = 0

for i in range(1000): 

    #do a few calculations

    progress += 1

    stop = datetime.now()
    execution_time = stop-start 

    remaining = execution_time * ( 1000 - progress )

    print("Progress:", progress, "%, estimated", remaining, "time remaining")
Run Code Online (Sandbox Code Playgroud)

但它似乎无法正常工作,因为它会长达几分钟,尽管循环总共需要 20 秒,并且在到达末尾时会迅速减少。

如何有效且正确地预测循环的剩余 时间

python for-loop forecasting

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

从系列中删除分钟和小时

早上好,

我有以下数据框(年,月,日,小时,秒):

print(df)

     Date               Price
2018-01-02 09:42:00       2
2018-01-02 09:46:00       4
2018-01-02 10:22:00       6
...
Run Code Online (Sandbox Code Playgroud)

我想得到,没有分钟和几秒钟:

print(final_df)

     Date               Price
2018-01-02                2
2018-01-02                4
2018-01-02                6
...
Run Code Online (Sandbox Code Playgroud)

我试过了:

df['Date'] = datetime.datetime.strptime(df['Date'], '%Y-%m-%d').date()
Run Code Online (Sandbox Code Playgroud)

但是它报告“ strptime()参数1必须是str,而不是Series”

python datetime pandas

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

Google Cloud:从 Postman 的 Json 获取授权令牌

我正在尝试使用 Postman 触发经过身份验证的 GCP 云功能。

为此,我创建了一个具有“Cloud Functions Invoker”角色的专用服务帐户,并下载了一个结构如下的 .json 密钥:

{
  "type": "service_account",
  "project_id": "xxx",
  "private_key_id": "xxx",
  "private_key": "-----BEGIN PRIVATE KEY-----\n1234=\n-----END PRIVATE KEY-----\n",
  "client_email": "xxx.iam.gserviceaccount.com",
  "client_id": "xxxx",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "xxx.iam.gserviceaccount.com"
}
Run Code Online (Sandbox Code Playgroud)

我尝试将整个“private_key”(-----BEGIN PRIVATE KEY-----\n1234=\n-----END PRIVATE KEY-----\n)粘贴为承载令牌,但我得到出现以下错误:

<title>401 Unauthorized</title>  
Run Code Online (Sandbox Code Playgroud)

现在,如何使用 GCP 中的 .json 文件通过 Postman 进行身份验证?我应该使用哪些参数?

google-cloud-platform postman bearer-token google-cloud-functions

4
推荐指数
1
解决办法
3809
查看次数

允许未经身份验证的参数不起作用

我正在通过 GitHub 和 Google Cloud Build 使用以下 .yaml 文件创建 CICD 管道:

# Cloud Function specifications
steps:
- name: 'gcr.io/cloud-builders/gcloud'
  args:
  - functions
  - deploy
  - hello_world
  - --source=./src
  - --trigger-http
  - --memory=1024MB
  - --max-instances=5
  - --runtime=python39
  - --region=europe-west6
  - --entry-point=predict
  - --allow-unauthenticated
Run Code Online (Sandbox Code Playgroud)

一切正常,功能部署正确;但是,每当我尝试调用它时,都会引发以下错误:

<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8">
    <title>401 Unauthorized</title>
</head>
Run Code Online (Sandbox Code Playgroud)

似乎 --allow-unauthenticated 参数无法正常工作。如何公开 API 并授予公众访问权限?

Predict 函数允许未经身份验证,hello_world 不允许

笔记:

如果我跑gcloud functions describe --project=XXXXXX --region=europe-west6 hello_world

我得到:

availableMemoryMb: 1024
buildId: 1234
entryPoint: predict
environmentVariables:
  ABC: '"discount"'
httpsTrigger:
  securityLevel: SECURE_OPTIONAL
  url: https://europe-west6-XXX.cloudfunctions.net/hello_world
ingressSettings: ALLOW_ALL …
Run Code Online (Sandbox Code Playgroud)

yaml google-cloud-platform google-cloud-functions cicd

3
推荐指数
1
解决办法
3309
查看次数

将零替换为不等于零的最后一个值

我有以下数据帧:

print(inventory_df)

      dt_op  Prod_1  Prod_2  Prod_n
1  10/09/18       5      50       2
2  11/09/18       4       0       0
3  12/09/18       2       0       0
4  13/09/18       0       0       0
5  14/09/18       4      30       1
Run Code Online (Sandbox Code Playgroud)

我想将值更改为零,使用最后一个值!=从零开始,在每列中,如下所示:

print(final_inventory_df)

      dt_op  Prod_1  Prod_2  Prod_n
1  10/09/18       5      50       2
2  11/09/18       4      50       2
3  12/09/18       2      50       2
4  13/09/18       2      50       2
5  14/09/18       4      30       1
Run Code Online (Sandbox Code Playgroud)

我怎么能这样做?

python pandas

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

从 Streamlit/Hydralit 中删除标题空白

我正在尝试从基于 Hydralit 的 Streamlit(v.1.1.0)应用程序中删除白色间距(如图所示;徽标和主页下方的两个空格。

我尝试过:

# 1
st.markdown(
        f""" <style>
        .reportview-container .main .block-container{{
            padding-top: 0 rem;
            padding-right: 0 rem;
            padding-left: 0 rem;
            padding-bottom: 0 rem;
        }} </style> """,
        unsafe_allow_html=True,
    )
# 2 
st.markdown("""
        <style>
               .css-18e3th9 {
                    padding-top: 0rem;
                    padding-bottom: 10rem;
                    padding-left: 5rem;
                    padding-right: 5rem;
                }
               .css-1d391kg {
                    padding-top: 3.5rem;
                    padding-right: 1rem;
                    padding-bottom: 3.5rem;
                    padding-left: 1rem;
                }
        </style>
        """, unsafe_allow_html=True)
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

但它们似乎都不起作用;如何压缩布局并有效减少徽标下方和页面第一个标题上方的空间?

html python streamlit

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

零填充熊猫列

我有以下数据框,其中col_1是整数类型:

print(df)

col_1 
100
200
00153
00164
Run Code Online (Sandbox Code Playgroud)

如果位数等于3,我想添加两个零。

final_col
00100
00200
00153
00164
Run Code Online (Sandbox Code Playgroud)

我尝试过:

df.col_1 = df.col_1.astype(int).astype(str)

df["final_col"] = np.where(len(df["col_1"]) == 3, "00" + df.col_1, df.col_1 )
Run Code Online (Sandbox Code Playgroud)

但是,它不会产生预期的输出(满足条件时,不会将两位数字相加)。

我该如何解决?

python numpy pandas

0
推荐指数
3
解决办法
276
查看次数