我有一个多线程函数,我想要一个使用状态栏tqdm。有没有一种简单的方法可以显示状态栏ThreadPoolExecutor?正是并行化部分使我感到困惑。
import concurrent.futures
def f(x):
return f**2
my_iter = range(1000000)
def run(f,my_iter):
with concurrent.futures.ThreadPoolExecutor() as executor:
function = list(executor.map(f, my_iter))
return results
run(f, my_iter) # wrap tqdr around this function?
Run Code Online (Sandbox Code Playgroud) 我想从正态分布中采样点,然后使用gganimate包一个一个地建立一个点图,直到最后一帧显示完整的点图。
适用于约 5,000 - 20,000 个点的更大数据集的解决方案至关重要。
这是我到目前为止的代码:
library(gganimate)
library(tidyverse)
# Generate 100 normal data points, along an index for each sample
samples <- rnorm(100)
index <- seq(1:length(samples))
# Put data into a data frame
df <- tibble(value=samples, index=index)
Run Code Online (Sandbox Code Playgroud)
df 看起来像这样:
> head(df)
# A tibble: 6 x 2
value index
<dbl> <int>
1 0.0818 1
2 -0.311 2
3 -0.966 3
4 -0.615 4
5 0.388 5
6 -1.66 6
Run Code Online (Sandbox Code Playgroud)
静态图显示了正确的点图:
# Create static version
plot <- ggplot(data=df, …Run Code Online (Sandbox Code Playgroud) 我想运行这个 D3 可视化
https://beta.observablehq.com/@mbostock/d3-zoomable-sunburst
作为一个独立的网页,就像这里的这个
https://bl.ocks.org/maybelinot/5552606564ef37b5de7e47ed2b7dc099
Observable 有导出到.html文件的功能吗?或者我需要改变什么才能使其独立?
我如何bs4在bookdown中使用主题,例如用于R4DS书的主题
在_output.yaml我看到以下代码,但它不适用于我的项目。
bookdown::bs4_book:
theme:
primary: "#637238"
repo: https://github.com/hadley/r4ds
includes:
in_header: [ga_script.html]
Run Code Online (Sandbox Code Playgroud)
当我尝试构建这本书时出现此错误
Error: 'bs4_book' is not an exported object from 'namespace:bookdown'
Execution halted
Run Code Online (Sandbox Code Playgroud) 我正在关注本教程。
我想使用Matplotlib创建一个散点图,该点内部为彩色,但具有黑色边框,例如此图:

但是,当我精确复制代码时,我得到了这个图。
这是代码:
colors = ['black', 'blue', 'purple', 'yellow', 'white', 'red', 'lime', 'cyan', 'orange', 'gray']
for i in range(len(colors)):
x = reduced_data_rpca[:, 0][digits.target == i]
y = reduced_data_rpca[:, 1][digits.target == i]
plt.scatter(x, y, c=colors[i])
plt.legend(digits.target_names, bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
plt.xlabel('First Principal Component')
plt.ylabel('Second Principal Component')
plt.title("PCA Scatter Plot")
plt.show()
Run Code Online (Sandbox Code Playgroud)
我尝试调整样式,但这没有帮助。
我正在处理药品标签的数据.文本总是使用动词短语"指示"来构造.
例如:
sentence = "Meloxicam tablet is indicated for relief of the signs and symptoms of osteoarthritis and rheumatoid arthritis"
Run Code Online (Sandbox Code Playgroud)
我已经使用SpaCy过滤到只包含"指示"一词的句子.
我现在需要一个将接受句子的函数,并返回作为'指示'对象的短语.所以对于这个例子,我调用的函数extract()将像这样运行:
extract(sentence)
>> 'relief of the signs and symptoms of osteoarthritis and rheumatoid arthritis'
Run Code Online (Sandbox Code Playgroud)
是否有使用spacy执行此操作的功能?
编辑:在'指示'之后简单拆分不适用于复杂的例子.
以下是一些例子:
'''丁丙诺啡和纳洛酮舌下片用于阿片类药物依赖的维持治疗,应作为完整治疗计划的一部分,包括咨询和社会心理支持丁丙诺啡和纳洛酮舌下片含有丁丙诺啡,部分阿片类激动剂和纳洛酮,阿片类药物拮抗剂并且适用于阿片类药物依赖的维持治疗 '''
'''氧氟沙星眼用溶液适用于治疗下列病症引起的下列细菌易感菌株引起的感染结膜炎革兰氏阳性菌革兰氏阴性菌金黄色葡萄球菌表皮葡萄球菌链球菌肺炎链球菌阴沟肠杆菌流感嗜血杆菌奇异变形虫铜绿假单胞菌角膜溃疡克阳性菌革兰氏阴性菌金黄色葡萄球菌表皮葡萄球菌链球菌肺炎链球菌铜绿假单胞菌粘质沙雷氏菌'''
我只想要大胆的部分.
我想在 XML 文件中搜索多个标签。
我可以单独评估这些命令:
tree.findall('.//title')
tree.findall('.//p')
Run Code Online (Sandbox Code Playgroud)
但我怎样才能同时评估它们呢?我正在寻找类似的语法.// title or .//p
我在 SO 帖子中尝试了这个命令
tree.findall('.//(p|title)')
Run Code Online (Sandbox Code Playgroud)
但我收到这个回溯错误SyntaxError: invalid descendant
我如何订购我的条形图,使其处于从最大到最小的顺序?我尝试了以下代码,但未达到预期效果。
我想要按“ b”,“ a”,“ c”(按计数)排序的条
df = pd.DataFrame([['a',2],['a',3],['b',4],['b',5],['b',4],['c',8]], columns=['Letters', 'Numbers'])
Letters Numbers
0 a 2
1 a 3
2 b 4
3 b 5
4 b 4
5 c 8
alt.Chart(df).mark_bar().encode(
alt.X('Letters:N'),
alt.Y('count():Q', sort=alt.EncodingSortField(field='count', op='count', order='ascending')))
Run Code Online (Sandbox Code Playgroud)
在 中Python,可以使用以下方法获取列表中值的计数Series.value_counts():
import pandas as pd
df = pd.DataFrame()
df['x'] = ['a','b','b','c','c','d']
df['y'] = list(range(1,7))
df['x'].value_counts()
c 2
b 2
a 1
d 1
Name: x, dtype: int64
Run Code Online (Sandbox Code Playgroud)
在 中R,我必须使用三个单独的命令。
df <- tibble(x=c('a','b','b','c','c','d'), y=1:6)
df %>% group_by(x) %>% summarise(n=n()) %>% arrange(desc(n))
x n
b 2
c 2
a 1
d 1
Run Code Online (Sandbox Code Playgroud)
在 R 中有更短/更惯用的方法吗?还是我最好编写自定义函数?
我有一个doc想要词形还原的 spaCy 。
例如:
import spacy
nlp = spacy.load('en_core_web_lg')
my_str = 'Python is the greatest language in the world'
doc = nlp(my_str)
Run Code Online (Sandbox Code Playgroud)
如何将 中的每个标记转换doc为其引理?