小编Blu*_*lue的帖子

如何实现 JavaScript 回调来更改 Bokeh 图标题

我只是想让用户能够更改散景图的标题。这是我尝试过的代码的最小示例。问题是如何进行回调。


from bokeh.io import show, output_file
from bokeh.plotting import figure
from bokeh.models import CustomJS, Button

fig = figure(title='title')
fig.line(x=[1,2,3], y=[1,2,3])


callback = CustomJS(args={'title':fig.title}, code="""title.text = text_input.get('value');
""")

text_input = TextInput(title="Add graph title", value='', callback=callback)


widgets_layout = column(text_input)


figures_layout = row(fig)


page_layout = row(widgets_layout, fig)


script, div = components(page_layout)
return render_to_response('fig.html', {'script': script, 'div': div})


Run Code Online (Sandbox Code Playgroud)

我没有收到任何错误,但当我在 TextInput 字段中输入新标题时没有任何反应。

有任何想法吗 ?

javascript bokeh

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

如何在 R 中删除第 99 个百分位数异常值

我只是想用 NA 分别替换每个组的异常值(高于 99% 的值)。我不知道如何在不创建一个全新的冗余数据框的情况下做到这一点。有任何想法吗 ?

group <- c('A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B')
var1 <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 50, 1, 2, 3, 4, 5, 6, 7, 8, 9, 50)
df = data.frame(group, var1)

unique_groups = unique(df$group)

df2 = data.frame()

for(g in 1:length(unique_groups)) {
  
  subset_df <- df[grep(unique_groups[1], df$group), ]

  quantiles <- quantile(subset_df$var1, c(.01, .99), na.rm = TRUE)
  
  subset_df$var1[subset_df$var1 > quantiles[2]] …
Run Code Online (Sandbox Code Playgroud)

r

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

如何在重复条目的熊猫中进行透视

如何以大熊猫为中心?我无法解决“重复条目”错误。输入和输出应如下所示。

import pandas as pd

input = pd.DataFrame({'measure': ['length','length','length','weight','weight','weight','sex','sex','sex'],
                      'species': [10, 10, 10, 10, 10, 10, 10, 10, 10],
                      'value': [1, 2, 3, 13, 45, 123, 0, 1, 1],
                      'set': [3, 3, 3, 3, 3, 3, 3, 3, 3]})

output = pd.DataFrame({'set': [3,3,3],
                       'species': [10, 10, 10],
                       'length': [1, 2, 3],
                       'weight': [13, 45, 123],
                       'sex': [0, 1, 1]})

test = input.pivot(index='set',columns='measure', values='value')

print(test)
Run Code Online (Sandbox Code Playgroud)

python pivot dataframe pandas

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

标签 统计

bokeh ×1

dataframe ×1

javascript ×1

pandas ×1

pivot ×1

python ×1

r ×1