我有一个自己构建的仪表板。我想增加更多的互动性。我想允许用户在下拉菜单中选择一个选项,并且数据表中显示的数据根据所述选择进行过滤
这就是我定义数据表的方式
html.Div([
dash_table.DataTable(
id='punchstats',
columns=[{'name': i, 'id': i} for i in punch_stats.columns],
data = punch_stats.to_dict('records'),
page_current=0,
page_size=2,
page_action='custom',
sort_action='custom',
sort_mode='multi',
style_table={'overflowX':'scroll',
'maxHeight':'300px'},
style_header={'backgroundColor':'rgb(30, 30, 30)'},
style_cell={'backgroundColor':'rgb(50,50,50)',
'color':'white'},
sort_by=[]),
])
Run Code Online (Sandbox Code Playgroud)
这些是我定义的下拉过滤器
dcc.Dropdown(
id='weight_class',
options=[{'label': i, 'value': i} for i in data['division'].unique()],
multi=True
),
dcc.Dropdown(
id='gender',
options=[{'label': i, 'value':i} for i in fight_outcomes['sex'].unique()],
multi=True
),
Run Code Online (Sandbox Code Playgroud)
这是应该根据下拉选择更新我的表的函数
@app.callback(
dash.dependencies.Output('punchstats','data'),
[dash.dependencies.Input('punchstats','page_current'),
dash.dependencies.Input('punchstats','page_size'),
dash.dependencies.Input('punchstats','sort_by'),
dash.dependencies.Input('weight_class','value'),
dash.dependencies.Input('gender','value')])
def update_punchstats(page_current,page_size,sort_by,weight_class,gender):
if weight_class is None or weight_class == []:
weight_class == WEIGHT_CLASS
if gender is None or …Run Code Online (Sandbox Code Playgroud) 我用热图构建了一个仪表板。但是我注意到 t=我的 y 轴中的一些标签没有显示。我只得到了有限的我不知道出了什么问题。这是我的仪表板:
\n\nimport dash\nimport dash_table\nimport plotly.graph_objs as go\nimport dash_html_components as html\nimport dash_core_components as dcc\nfrom dash.dependencies import Input,Output\nimport pandas as pd\nimport os\nimport numpy as np\n#correlation dataframe\ncorrelation_df = supervisor[[\'Caracter\xc3\xadsticas (D)\', \'Caracter\xc3\xadsticas (I)\',\n \'Caracter\xc3\xadsticas (S)\', \'Caracter\xc3\xadsticas (C)\', \'Motivaci\xc3\xb3n (D)\',\n \'Motivaci\xc3\xb3n (I)\', \'Motivaci\xc3\xb3n (S)\', \'Motivaci\xc3\xb3n (C)\', \'Bajo Stress (D)\',\n \'Bajo Stress (I)\', \'Bajo Stress (S)\', \'Bajo Stress (C)\',\'span\',\'Mean Team Performance\',\'employment span\',\'Pay to team size ratio\']]\ncorrelation_df = correlation_df.corr()\ncorr_fig = go.Figure()\ncorr_fig.add_trace(go.Heatmap(\n z= correlation_df.values,\n x= [\'Caracter\xc3\xadsticas (D)\', \'Caracter\xc3\xadsticas (I)\',\n \'Caracter\xc3\xadsticas (S)\', \'Caracter\xc3\xadsticas (C)\', \'Motivaci\xc3\xb3n …Run Code Online (Sandbox Code Playgroud) 我想在路径中找到匹配的字符串并使用 np.select 创建一个新列,其中的标签取决于我找到的匹配项。
这是我写的
import numpy as np
conditions = [a["properties_path"].str.contains('blog'),
a["properties_path"].str.contains('credit-card-readers/|machines|poss|team|transaction_fees'),
a["properties_path"].str.contains('signup|sign-up|create-account|continue|checkout'),
a["properties_path"].str.contains('complete'),
a["properties_path"] == '/za/|/',
a["properties_path"].str.contains('promo')]
choices = [ "blog","info_pages","signup","completed","home_page","promo"]
a["page_type"] = np.select(conditions, choices, default=np.nan)
Run Code Online (Sandbox Code Playgroud)
但是,当我运行此代码时,我收到此错误消息:
ValueError:condlist 中的无效条目 0:应该是布尔值 ndarray
这是我的数据示例
3124465 /blog/ts-st...
3124466 /card-machines
3124467 /card-machines
3124468 /card-machines
3124469 /promo/our-gift-to-you
3124470 /create-account/v1
3124471 /za/signup/
3124472 /create-account/v1
3124473 /sign-up
3124474 /za/
3124475 /sign-up/cart
3124476 /checkout/
3124477 /complete
3124478 /card-machines
3124479 /continue
3124480 /blog/article/get-car...
3124481 /blog/article/get-car...
3124482 /za/signup/
3124483 /credit-card-readers
3124484 /signup
3124485 /credit-card-readers
3124486 /create-account/v1
3124487 /credit-card-readers
3124488 …Run Code Online (Sandbox Code Playgroud) 试图从我的数据中过滤掉某一天,当我尝试运行我的代码时,我没有得到任何结果(这是不准确的,因为有那一天的数据)。
这是我正在使用的代码:
a['datetime'] = pd.to_datetime(a['datetime'])
start_date = pd.to_datetime('2019-09-01')
end_date = pd.to_datetime('2019-10-01')
sept = a[a['datetime'].between(start_date, end_date)]
day1 = pd.to_datetime('2019-09-11')
(sept['datetime'] == day1).sum()
Run Code Online (Sandbox Code Playgroud)
这是我的数据示例
3 2019-09-11 06:59:02.715641
13 2019-09-12 11:16:53.061871
24 2019-09-02 06:50:37.347313
27034 2019-09-15 11:57:34.582988
27163 2019-09-01 13:38:34.169917
31708 2019-09-17 07:45:50.693893
32883 2019-09-06 13:27:56.161920
33645 2019-09-17 10:02:11.010567
33657 2019-09-01 15:55:42.492608
57825 2019-09-17 11:25:19.405100
57836 2019-09-04 20:12:10.853341
57837 2019-09-04 20:12:00.959338
Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个由每个ID的唯一值组成的列(每个ID都有与其关联的许多行),如果该ID的任何行都与已回答的标签相关联,则所有与该ID关联的行都应标记为回答。如果与ID关联的所有行都具有未回答的标记,则所有行都应标记为未回答(当前发生的情况)
这是我编写的代码:
将numpy导入为np
conds = [file.data__answered_at.isna(),file.data__answered_at.notna()]
choices = ["not answered","answered"]
file['call_status'] = np.select(conds,choices,default=np.nan)
data__id call_status rank
1 answered 1
1 not_answered 2
1 answered 3
2 not_answered 1
2 answered 2
3 not_answered 1
4 answered 1
4 not_answered 2
5 not_answered 1
5 not_answered 2
Run Code Online (Sandbox Code Playgroud)
在这种情况下,期望的结果将是
data__id call_status rank
1 answered 1
1 answered 2
1 answered 3
2 answered 1
2 answered 2
3 not_answered 1
4 answered 1
4 answered 2
5 not_answered 1
5 not_answered 2
Run Code Online (Sandbox Code Playgroud) 获取错误消息
ERROR: The requested version of Python
('~/.virtualenvs/python_environment/bin/python') cannot be used, as
another version of Python ('/usr/bin/python3') has already been
initialized. Please restart the R session if you need to attach
reticulate to a different version of Python.
Error in value[[3L]](cond) :
failed to initialize requested version of Python
Calls: local ... tryCatch -> tryCatchList -> tryCatchOne -> <Anonymous>
In addition: Warning message:
In py_initialize(config$python, config$libpython, config$pythonhome, :
'.Random.seed[1]' is not a valid integer, so ignored
Execution halted
Run Code Online (Sandbox Code Playgroud)
在闪亮的应用程序上加载我的网络应用程序时。该应用程序仅在我刷新网页后加载
这是我的代码的一部分: …
我想计算每个销售代理不同时间段之间价值的绝对差异。
所以从这个数据集:
Report month ID Vendedor sum count Rental Charge
2018-07-01 803621.0 780.81 42 4
2018-07-01 900000.0 100.90 20 5
2018-08-01 803621.0 1132.71 77 3
2018-08-01 900000.0 1000.10 10 2
Run Code Online (Sandbox Code Playgroud)
我想得到这样的结果:
Report month ID Vendedor sum count Rental Charge Diff
2018-07-01 803621.0 780.81 42 4 0
2018-08-01 803621.0 1132.71 77 3 351.90
2018-07-01 900000.0 100.90 20 5 0
2018-08-01 900000.0 1000.10 10 2 899.20
Run Code Online (Sandbox Code Playgroud)
这是我尝试过的:
two['pct_change'] = one.groupby(['Report month','ID Vendedor'])['sum'].pct_change()
Run Code Online (Sandbox Code Playgroud)
这是我得到的结果:
Report month ID Vendedor sum count Rental Charge Pct_change …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建一个网络应用程序,它将清理 csv 并返回 pdf 格式的图表。
因为我是构建网络应用程序和烧瓶的新手。我尝试从构建一个简单的 Web 应用程序开始,该应用程序允许用户上传 csv 格式的文件。但是,当我尝试在 bash 上运行该应用程序时,我收到以下错误消息:
(venv) bash-3.2$ python main.py
Traceback (most recent call last):
File "main.py", line 5, in <module>
"execution_count": null,
NameError: name 'null' is not defined
Run Code Online (Sandbox Code Playgroud)
这是我迄今为止用来构建网络应用程序的代码。我在 Jupyter 中编写了这段代码,将其下载为 .py 文件,并尝试在 bash 上运行该文件
from pprint import pprint as pp
from flask import Flask, flash,redirect,render_template,request,url_for
from werkzeug.utils import secure_filename
upload_folder = '/path/to/the/uploads'
allowed_exts = set(['csv','pdf'])
app = Flask(__name__)
app.config['upload_folder'] = upload_folder
def allowed_f(file):
return '.' in file and \
file.rsplit('.',1)[1].lower() in allowed_exts …Run Code Online (Sandbox Code Playgroud)