我有一个简单的问题:
当您使用Beautiful Soup刮取网站的某个部分时,您可以使用data.find()/ data.findAll()或data.select()
现在的问题是..find()和.select()方法之间是否存在显着差异?(例如,在表现或灵活性方面,或......)
还是他们一样?
亲切的问候
在 sklearn.metrics.f1_score 中,f1 分数有一个名为“average”的参数。宏观、微观、加权和样本是什么意思?请详细说明,因为在文档中,没有正确解释。或者简单地回答以下问题:
我正在尝试重新创建训练模型的预测,但我不知道如何保存模型。例如,我想保存训练好的高斯处理回归器模型并在训练模型后重新创建预测。我用来训练模型的包是 scikit-learn。
kernel = DotProduct() + WhiteKernel()
gpr = GaussianProcessRegressor(kernel=kernel,random_state=0)
gpr.fit(X,y)
Run Code Online (Sandbox Code Playgroud) 我试图在 plotly,python 中绘制堆叠条形图时自定义图例的顺序。
data = [
go.Bar(
y=df['sid'], # assign x as the dataframe column 'x'
x=df['A'],
orientation='h',
name='A'
),
go.Bar(
y=df['sid'],
x=df['B'],
orientation='h',
name='B'
),
]
layout = go.Layout(
barmode='stack',
title=f'{measurement}',
xaxis=dict(
title='Count',
dtick=0),
yaxis=dict(
tickfont=dict(
size=10,
),
dtick=1)
)
fig = go.Figure(data=data, layout=layout)
plot(fig, filename='plot.html')
Run Code Online (Sandbox Code Playgroud)
图例的顺序以相反的顺序出现(即从下到上)。我想将data.
我看到了此处为 java建议的选项。不确定如何在python中实现。
有人可以建议如何颠倒顺序吗?
编辑:在生成的图像中,图例的顺序是
B
A
Run Code Online (Sandbox Code Playgroud)
所需订单:
A
B
Run Code Online (Sandbox Code Playgroud) 我无法让 seaborn 的relplot函数在每行上使用不同的 y 轴进行绘图(同时每列共享 x 轴)。
我可以看到seaborn 中的FacetGrid和catplot方法都有一个 sharex/sharey 关键字参数可以解决我的问题,但是我在relplot.
如果打算通过访问relplot单独返回的子图,有什么方法可以解决这个问题吗?我想继续使用 relplot,因为它可以完美地处理图形大小,但FacetGrid在该领域存在很多问题。谢谢。
如何增加seaborn箱线图中两个特定框之间的空间?在提示数据集中,如何修改周六和周日之间的间距而不影响其他框。我已经在数据框中包含了空列,但使用此解决方法无法控制间距。
%matplotlib inline
import seaborn as sns
tips = sns.load_dataset("tips")
ax = sns.boxplot(x="day", y="total_bill", data=tips)
Run Code Online (Sandbox Code Playgroud)
我正在尝试执行代码,但出现错误。
import pandas as pd
import numpy as np
pd.Series([1, 2, np.nan, 4], dtype=pd.Int64Dtype())
Run Code Online (Sandbox Code Playgroud)
我希望输出为:
Out[14]:
0 1
1 2
2 NaN
3 4
dtype: Int64
Run Code Online (Sandbox Code Playgroud) sklearn 提供transform()了应用 one-hot 编码器的方法。
使用transform()方法,fit_transform()在调用transform()方法之前需要,否则
np.array([[1, 1], [2, 1], [3, 2], [np.nan, 2]])
from sklearn.impute import SimpleImputer
my_imputer = SimpleImputer()
my_imputer.transform(df)
Run Code Online (Sandbox Code Playgroud)
错误出现
NotFittedError: 这个 SimpleImputer 实例尚未安装。在使用此方法之前,使用适当的参数调用 'fit'。
fit_transform()之前打电话transform()
my_imputer.fit_transform(df)
my_imputer.transform(df)
Run Code Online (Sandbox Code Playgroud)
修复这个错误。
问题是,为什么transform()需要fit_transform()?
我想将 Plotly 图表嵌入到我自己的 html 文件中。使用 Dash,我可以在 API 本地服务器中生成相同的图表。
但是对于我自己的 HTML 文件,我没有得到任何解决方案:
我的达世币解决方案:
import dash
import dash_core_components as dcc
import dash_html_components as html
app = dash.Dash()
app.layout = html.Div(children=[
html.H1(children='Dash Tutorials'),
dcc.Graph(
id='example',
figure={
'data': [
{'x': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 'y': [9, 6, 2, 1, 5, 4, 6, 8, 1, 3], 'type': 'bar', 'name': 'Boats'},
{'x': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 'y': [19, 36, 12, 1, 35, 4, 6, …Run Code Online (Sandbox Code Playgroud) 我正在尝试编写一个 Python 程序来从 Google 趋势 (GT) 中收集数据 - 具体来说,我想自动打开 URL 并访问折线图中显示的特定值:
我会很高兴下载 CSV 文件,或者通过网络抓取值(根据我对 Inspect Element 的阅读,清理数据只需要一两个简单的拆分)。我要进行许多搜索(许多不同的关键字)
我正在创建许多 URL 来从 Google 趋势中收集数据。我使用了测试搜索中的实际 URL。URL 示例:https : //trends.google.com/trends/explore?q= sports%20cars &geo= US 在浏览器上实际搜索此 URL 会显示相关的 GT 页面。当我尝试通过程序访问它时,问题就出现了。
我看到的大多数回复都建议使用来自 Pip 的公共模块(例如 PyTrends 和“非官方 Google Trends API”)——我的项目经理坚持我不使用不是由站点直接创建的模块(即:API 是可以接受的,但仅限于官方的 Google API)。只有 BeautifulSoup 被批准为插件(不要问为什么)。
下面是我尝试过的代码示例。我知道这是基本的,但是在我收到的第一个请求中:
HTTPError:HTTP 错误 429:未知”:请求过多。
对其他问题的一些回答提到了 Google Trends API - 这是真的吗?我在官方 API 上找不到任何文档。
这是另一篇文章,其中概述了我尝试过但对我不起作用的解决方案:
https://codereview.stackexchange.com/questions/208277/web-scraping-google-trends-in-python
url = 'https://trends.google.com/trends/explore?q=sports%20cars&geo=US'
html = urlopen(url).read()
soup = bs(html, 'html.parser')
divs = soup.find_all('div')
return divs
Run Code Online (Sandbox Code Playgroud) python ×9
python-3.x ×6
scikit-learn ×3
plotly ×2
seaborn ×2
bar-chart ×1
boxplot ×1
html ×1
legend ×1
matplotlib ×1
metrics ×1
numpy ×1
pandas ×1
plotly-dash ×1
request ×1
save ×1
web-scraping ×1