小编ged*_*133的帖子

证书验证失败:无法获取本地颁发者证书 python 请求

我正在尝试使用一个非常简单的 python 请求,requests.get但使用此代码收到以下错误:

url = 'https://www.tesco.com/'
status = requests.get(url)
Run Code Online (Sandbox Code Playgroud)

错误:

requests.exceptions.SSLError: HTTPSConnectionPool(host='www.tesco.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)')))
Run Code Online (Sandbox Code Playgroud)

谁能向我解释如何解决这个问题,更重要的是这个错误意味着什么?

非常感谢

python web-scraping python-requests

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

即使安装了 kaleido,保存的绘图图像也无法与 kaleido 一起使用

我正在尝试将一个简单的绘图保存到目录中。我知道它需要 kaleido (我有版本“0.2.1”)并且至少还需要安装“5.3.1”。

但是尝试保存图像时出现以下错误:

fig.write_image(path)

ValueError: 
Image export using the "kaleido" engine requires the kaleido package,
which can be installed using pip:
$ pip install -U kaleido
Run Code Online (Sandbox Code Playgroud)

当所有必需的包都存在时,为什么会发生这种情况?

python plotly kaleido

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

尽管使用 \centering,Latex 中的图形并未居中

我对 LaTex 非常陌生,正在尝试将图形居中。

我尝试使用和float来使用该包,我尝试添加并尝试将图像包装起来,但似乎没有任何效果。[h][H]\centering\begin{center} \end{centering}

我的完整代码是这样的

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{float}
\graphicspath{ {images/} }

\title{Dissertation}
\author{GC}
\date{\today}


\begin{document}

\maketitle

\section{Introduction}
\begin{figure}[H]
    \centering
    \includegraphics{my_grades}
    \caption{grades plot}
    \label{fig:grade}
\end{figure}

This figure does not seem to want to centre

\end{document}
Run Code Online (Sandbox Code Playgroud)

编译文档中的这个图看起来就是这样。如果有人可以帮助我理解为什么这不想移动那就太好了:

图像

latex

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

ValueError: Axes 实例参数未在图中找到,同名问题没有答案

我正在尝试创建一个 seaborn Facetgrid 来绘制我的 dataFrame 十项全能中所有列的正态分布。数据如下所示:

      P100m   Plj  Psp  Phj  P400m  P110h   Ppv  Pdt  Pjt  P1500
0       938  1061  773  859    896    911   880  732  757    752
1       839   975  870  749    887    878   880  823  863    741
2       814   866  841  887    921    939   819  778  884    691
3       872   898  789  878    848    879   790  790  861    804
4       892   913  742  803    816    869  1004  789  854    699
 ...   ...  ...  ...    ...    ...   ...  ...  ... …
Run Code Online (Sandbox Code Playgroud)

python seaborn

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

dash 应用程序拒绝启动:“127.0.0.1 拒绝连接。”

我正在尝试运行示例 dash 应用程序,但在尝试运行时,浏览器说它拒绝连接。我已经检查过,谷歌浏览器可以通过防火墙访问。

示例代码是:

import dash
import dash_core_components as dcc
import dash_html_components as html

external_stylesheets = ['https://codepen.io/chriddyp/pen/bWLwgP.css']

app = dash.Dash(__name__, external_stylesheets=external_stylesheets)

app.layout = html.Div(children=[
html.H1(children='Hello Dash'),

html.Div(children='''
    Dash: A web application framework for Python.
'''),

dcc.Graph(
    id='example-graph',
    figure={
        'data': [
            {'x': [1, 2, 3], 'y': [4, 1, 2], 'type': 'bar', 'name': 'SF'},
            {'x': [1, 2, 3], 'y': [2, 4, 5], 'type': 'bar', 'name': u'Montréal'},
        ],
        'layout': {
            'title': 'Dash Data Visualization'
        }
    }
)
])

if __name__ == '__main__':
    app.run_server(debug=True) …
Run Code Online (Sandbox Code Playgroud)

python dashboard plotly-dash

6
推荐指数
2
解决办法
6354
查看次数

Plotly:如何使用折线图的下拉列表更新绘图数据?

我正在尝试将下拉菜单添加到绘图线图中,该图在选择时更新图形数据源。我的数据有 3 列,如下所示:

1               Country  Average House Price (£)       Date
0  Northern Ireland                      47101.0 1992-04-01
1  Northern Ireland                      49911.0 1992-07-01
2  Northern Ireland                      50174.0 1992-10-01
3  Northern Ireland                      46664.0 1993-01-01
4  Northern Ireland                      48247.0 1993-04-01
Run Code Online (Sandbox Code Playgroud)

Country 列包含英国的 4 个国家/地区,用于使用color参数为每个国家/地区创建单独的行。我有 4 个不同的数据框用于不同的住房类型,例如all_dwellings,first_timebuyers并且在尝试指定updatemenusargs 时,似乎我无法使用数据框格式。这是创建整个图形的代码。

lineplt = px.line(data_frame = all_dwellings,
              x='Date',
              y='Average House Price (£)',
              color= 'Country',
              hover_name='Country',
              color_discrete_sequence=['rgb(23, 153, 59)','rgb(214, 163, 21)','rgb(40, 48, 165)', 'rgb(210, 0, 38)']
              )
updatemenus = [
{'buttons': [
            { …
Run Code Online (Sandbox Code Playgroud)

python pandas plotly plotly-dash

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

类型错误:不可散列的类型:“切片”pandas DataFrame 列

这可能很简单,但我找不到解释,而且这种情况经常发生在我身上。

我正在尝试从Rate1E结束的列中选择值,并查看 pandas DataFrame 中符合上述条件的选定行的3.5其余行。energy之前有人给过我答案,我简单地改为文字如下:

energy = energy.loc[energy[:, 'Rate1E'] >= 3.5]
print(energy.loc[:, 'Rate1E'])
Run Code Online (Sandbox Code Playgroud)

然而我再次发现自己犯了错误:

TypeError: unhashable type: 'slice'
Run Code Online (Sandbox Code Playgroud)

网上的解决方案建议.loc就是答案。有人知道如何修复代码或者更好地向我解释为什么我似乎总是遇到这个错误。

谢谢。

python indexing series dataframe pandas

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

seaborn.pairplot() 改变每个图形的颜色

我试图pairplot用单独的颜色为每个图形制作一个简单的图形。我不知道这是否可行,因为我没有使用hue.

我的数据集是这样的:

      High Jump  Discus Throw  Long Jump
0           859           732       1061
1           749           823        975
2           887           778        866
3           878           790        898
4           803           789        913
     ...           ...        ...
7963        714           571        760
7964        767           573        845
7965        840           461        804
7966        758           487        720
7967        714           527        809
Run Code Online (Sandbox Code Playgroud)

我的代码和图表如下所示:

t = sns.pairplot(new)
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

有什么办法可以让这个颜色更鲜艳吗?

python seaborn

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

使用相同索引并行遍历 2 个列表

我试图并行遍历两个列表的列表索引,以便将第一个列表中的第 i 个数字和第二个列表中的第 i 个数字之间的范围附加到一个新变量中,每个范围都在其自己的列表中。我不想包含范围中的第一个数字,因此对于第一次迭代,输出将是[2,3]列表如下:

def_idx = [1,13,23]
return_id = [3,14,25]
line_idx = []`
Run Code Online (Sandbox Code Playgroud)

所需的输出line_idx如下: line_idx = [[2, 3], [14], [24, 25]]

由于列表太多,我对此的尝试没有奏效:

line_idx = []
for i, j in enumerate(def_idx):
    line_idx.append([list(range(j + 1, return_idx[i] + 1))])
Run Code Online (Sandbox Code Playgroud)

任何帮助将不胜感激,如果问题不清楚,那么我很乐意提供进一步的解释。

python loops list

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

带有 lightgbm 的 GridSearchCV 需要不使用 fit() 方法?

我正在尝试使用GridSearchCVLightGBMsklearn估计器,但在构建搜索时遇到问题。

我要构建的代码如下所示:

d_train = lgb.Dataset(X_train, label=y_train)
params = {}
params['learning_rate'] = 0.003
params['boosting_type'] = 'gbdt'
params['objective'] = 'binary'
params['metric'] = 'binary_logloss'
params['sub_feature'] = 0.5
params['num_leaves'] = 10
params['min_data'] = 50
params['max_depth'] = 10

clf = lgb.train(params, d_train, 100)

param_grid = {
    'num_leaves': [10, 31, 127],
    'boosting_type': ['gbdt', 'rf'],
    'learning rate': [0.1, 0.001, 0.003]
    }


gsearch = GridSearchCV(estimator=clf, param_grid=param_grid)
lgb_model = gsearch.fit(X=train, y=y)
Run Code Online (Sandbox Code Playgroud)

但是我遇到了以下错误:

TypeError: estimator should be an estimator implementing 'fit' method, 
          <lightgbm.basic.Booster object at 0x0000014C55CA2880> …
Run Code Online (Sandbox Code Playgroud)

python scikit-learn grid-search lightgbm

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

当“fig.show()”调用时,绘图不加载Fig

我试图distplot在 PyCharm IDE 中制作并显示一个绘图,但它尝试加载的浏览器似乎永远缓冲。我的数据和图表是这样的:

import plotly.figure_factory as ff

hist_data = 
[[23740.0, 66440.0, 47890.0, 40632.0, 51778.0, 59966.0, 92433.0, 101595.0, 53863.0, 27279.0, 49620.0, 14981.0], 
[32566.0, 95661.0, 69957.0, 62255.0, 73688.0, 90606.0, 163077.0, 151885.0, 80432.0, 39790.0, 76275.0, 23061.0], 
[41811.0, 122388.0, 87849.0, 80795.0, 98960.0, 123870.0, 245555.0, 204934.0, 105540.0, 49233.0, 98183.0, 29583.0]]


# Group data together
group_labels = ['1997', '2007', '2017']

fig = ff.create_distplot(hist_data, group_labels, bin_size=.2)
fig.show()
Run Code Online (Sandbox Code Playgroud)

我不认为这是代码的问题,它似乎与调用图形有关。该代码是为了可重复性。如果有人知道如何调试它,那就太好了。

python plotly

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