我正在使用以下Dockerfile构建一个docker容器:
FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install -y python python-dev python-pip
ADD . /app
RUN apt-get install -y python-scipy
RUN pip install -r /arrc/requirements.txt
EXPOSE 5000
WORKDIR /app
CMD python app.py
Run Code Online (Sandbox Code Playgroud)
一切顺利,直到我运行图像并得到以下错误:
**********************************************************************
Resource u'tokenizers/punkt/english.pickle' not found. Please
use the NLTK Downloader to obtain the resource: >>>
nltk.download()
Searched in:
- '/root/nltk_data'
- '/usr/share/nltk_data'
- '/usr/local/share/nltk_data'
- '/usr/lib/nltk_data'
- '/usr/local/lib/nltk_data'
- u''
**********************************************************************
Run Code Online (Sandbox Code Playgroud)
我以前遇到过这个问题,这里讨论但是我不知道如何使用Docker来解决它.我试过了:
CMD python
CMD import nltk
CMD nltk.download()
Run Code Online (Sandbox Code Playgroud)
以及:
CMD python -m nltk.downloader …
Run Code Online (Sandbox Code Playgroud) 我有一个看起来如下的df:
id item color
01 truck red
02 truck red
03 car black
04 truck blue
05 car black
Run Code Online (Sandbox Code Playgroud)
我正在尝试创建一个看起来像这样的df:
item color count
truck red 2
truck blue 1
car black 2
Run Code Online (Sandbox Code Playgroud)
我试过了
df["count"] = df.groupby("item")["color"].transform('count')
Run Code Online (Sandbox Code Playgroud)
但它并不是我所寻找的.
任何指导表示赞赏
我有两个独立的pandas数据帧(df1
和df2
),它们有多个列,但只有一个是共同的('text').
我想找到在列的任何行中df2
没有匹配df2
且df1
具有共同点的每一行.
DF1
A B text
45 2 score
33 5 miss
20 1 score
Run Code Online (Sandbox Code Playgroud)
DF2
C D text
.5 2 shot
.3 2 shot
.3 1 miss
Run Code Online (Sandbox Code Playgroud)
结果df(删除包含未命中的行,因为它出现在df1中)
C D text
.5 2 shot
.3 2 shot
Run Code Online (Sandbox Code Playgroud)
是否可以isin
在此方案中使用该方法?
我有两个长度相等的字符串,想要匹配具有相同索引的单词.我也试图匹配连续比赛,这是我遇到麻烦的地方.
例如,我有两个字符串
alligned1 = 'I am going to go to some show'
alligned2 = 'I am not going to go the show'
Run Code Online (Sandbox Code Playgroud)
我要找的是获得结果:
['I am','show']
Run Code Online (Sandbox Code Playgroud)
我目前的代码如下:
keys = []
for x in alligned1.split():
for i in alligned2.split():
if x == i:
keys.append(x)
Run Code Online (Sandbox Code Playgroud)
这给了我:
['I','am','show']
Run Code Online (Sandbox Code Playgroud)
任何指导或帮助将不胜感激.
我有一个单词列表例如:
words = ['one','two','three four','five','six seven']
#quote缺失了
我正在尝试创建一个新列表,列表中的每个项目只有一个单词,所以我会:
words = ['one','two','three','four','five','six','seven']
最好的做法是将整个列表加入一个字符串,然后将字符串标记化吗?像这样的东西:
word_string = ' '.join(words)
tokenize_list = nltk.tokenize(word_string)
或者有更好的选择吗?
例如'i cant sleep what should i do'
,我有一个字符串以及包含在字符串中的短语'cant sleep'
。我想要完成的是在短语周围获得一个 n 大小的窗口,即使两边都没有 n 个单词。因此,在这种情况下,如果我的窗口大小为 2(短语的任一大小上都有 2 个单词),我会想要'i cant sleep what should'
.
这是我当前尝试找到 2 的窗口大小的解决方案,但是当短语左侧或右侧的单词数小于 2 时失败,我也希望能够使用不同的窗口大小。
import re
sentence = 'i cant sleep what should i do'
phrase = 'cant sleep'
words = re.findall(r'\w+', sentence)
phrase_words = re.findall(r'\w+', phrase)
print sentence_words[left-2:right+3]
left = sentence_words.index(span_words[0])
right = sentence_words.index(span_words[-1])
print sentence_words[left-2:right+3]
Run Code Online (Sandbox Code Playgroud) 我有一个列表列表,如下所示:
a = [['he', 'goes'],
['he does'],
['one time'],
[('he','is'), ('she', 'went'), ('they', 'are')],
['he', 'must'],
['they use']]
Run Code Online (Sandbox Code Playgroud)
我试图压缩列表,使它只是一个没有元组的列表列表.例如:
a = [['he', 'goes'],
['he does'],
['one time'],
['he','is'],
['she', 'went'],
['they', 'are'],
['he', 'must'],
['they use']]
Run Code Online (Sandbox Code Playgroud)
我尝试过使用itertools.chain.from_iterable()
平坦化所有嵌套列表.
我有一个包含 ~200,000 行的 Pandas 数据框,我想创建 5 个随机样本,每个样本 1000 行,但是我不希望这些样本中的任何一个包含同一行两次。
要创建我一直使用的随机样本:
import numpy as np
rows = np.random.choice(df.index.values, 1000)
sampled_df = df.ix[rows]
Run Code Online (Sandbox Code Playgroud)
然而,仅仅这样做几次就会冒着重复的风险。处理这个问题的最好方法是跟踪每次采样哪些行?
我有两个数据框df1
和df2
. df1
包含列subject_id
和time
且df2
包含列subject_id
和final_time
。我想要做的是为每个subject_id
indf1
添加一列,其中包含 final_time
fromdf2
但仅来自于subject_ids
中包含的df1
。我已经尝试过df1.merge(df2,how='left')
,但仍然得到了所有更长subject_id
的df2
并且包含许多重复的“subject_id”。
我正在寻找的示例:
df1
subject_id time
0 15 12:00
1 20 12:05
2 21 12:10
3 25 12:00
df2
subject_id final_time
0 15 12:30
1 15 12:30
2 15 12:30
3 20 12:45
4 20 12:45
5 21 12:50
6 25 1:00
7 25 1:00
8 25 …
Run Code Online (Sandbox Code Playgroud) 我有一个关键字列表以及一个包含文本列的 DF。我试图过滤掉文本字段中的文本包含其中一个关键字的每一行。我相信我正在寻找的是类似于该.isin
方法的东西,但是当我在文本中搜索不完全匹配的子字符串时,它可以采用正则表达式参数。
我拥有的:
keys = ['key','key2']
A Text
0 5 Sample text one
1 6 Sample text two
2 3 Sample text three key
3 4 Sample text four key2
Run Code Online (Sandbox Code Playgroud)
我想删除文本中包含键的任何行,这样我最终会得到:
A Text
0 5 Sample text one
1 6 Sample text two
Run Code Online (Sandbox Code Playgroud)