我需要将多行两列data.frame转换为命名字符向量.我data.frame会是这样的:
dd = data.frame(crit = c("a","b","c","d"),
name = c("Alpha", "Beta", "Caesar", "Doris")
)
Run Code Online (Sandbox Code Playgroud)
我真正需要的是:
whatiwant = c("a" = "Alpha",
"b" = "Beta",
"c" = "Caesar",
"d" = "Doris")
Run Code Online (Sandbox Code Playgroud) 我使用twitteR包从twitter中提取推文并将其保存到文本文件中.
我在语料库上进行了以下操作
xx<-tm_map(xx,removeNumbers, lazy=TRUE, 'mc.cores=1')
xx<-tm_map(xx,stripWhitespace, lazy=TRUE, 'mc.cores=1')
xx<-tm_map(xx,removePunctuation, lazy=TRUE, 'mc.cores=1')
xx<-tm_map(xx,strip_retweets, lazy=TRUE, 'mc.cores=1')
xx<-tm_map(xx,removeWords,stopwords(english), lazy=TRUE, 'mc.cores=1')
Run Code Online (Sandbox Code Playgroud)
(使用mc.cores = 1和lazy = True,否则Mac上的R运行错误)
tdm<-TermDocumentMatrix(xx)
Run Code Online (Sandbox Code Playgroud)
但是这个术语文档矩阵有很多奇怪的符号,无意义的单词等.如果推文是
RT @Foxtel: One man stands between us and annihilation: @IanZiering.
Sharknado‚Äã 3: OH HELL NO! - July 23 on Foxtel @SyfyAU
Run Code Online (Sandbox Code Playgroud)
清理完推文后,我只想留下适当的完整英文单词,即句子/短语无效(用户名,缩短的单词,网址)
例:
One man stands between us and annihilation oh hell no on
Run Code Online (Sandbox Code Playgroud)
(注意:tm包中的转换命令只能删除停用词,标点符号空格以及转换为小写)
上下文:\n这是问题https://github.com/pypa/pip/issues/6717#issue-468204416我面临\n并试图通过\n https://github.com/pypa/pip
解决/问题/6717#issuecomment-511652167
我想用
\n\n--no-build-isolation\nRun Code Online (Sandbox Code Playgroud)\n\n在 py2.7 venv 中如果我这样做:
\n\npip install bottleneck==1.2.1 --no-build-isolation\n\nCollecting bottleneck==1.2.1\nCollecting numpy (from bottleneck==1.2.1)\n Downloading https://files.pythonhosted.org/packages/d7/b1/3367ea1f372957f97a6752ec725b87886e12af1415216feec9067e31df70/numpy-1.16.5-cp27-cp27mu-manylinux1_x86_64.whl (17.0MB)\n 100% |\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88\xe2\x96\x88| 17.0MB 1.2MB/s \nInstalling collected packages: numpy, bottleneck\nSuccessfully installed bottleneck-1.2.1 numpy-1.16.5\nYou are using pip version 18.0, however version 19.2.3 is available.\nYou should consider upgrading via the \'pip install --upgrade pip\' command.\n\nRun Code Online (Sandbox Code Playgroud)\n\n安装得很好
\n\n$ cat abc.txt \nbottleneck==1.2.1, --no-build-isolation\nRun Code Online (Sandbox Code Playgroud)\n\n但
\n\n$pip install -r abc.txt\nUsage: pip [options]\n\nInvalid requirement: bottleneck==1.2.1, --no-build-isolation\npip: error: …Run Code Online (Sandbox Code Playgroud) 这个问题与我的另一个问题有关:使用sox和python基于时间戳列表来区分音频区域
如果 q= [[0.0,4.0], [10.0,12.0], [15.0,20.0], [21.0,28.0], [32.0,36.0],[41.0,44.0]]
新列表q'应该是 [4.0,10.0],[12.0,15.0],[20.0,21.0],[28.0,32.0], [36.0,41.0]]
我做的是以下内容:
import numpy
q= [[0.0,4.0], [10.0,12.0], [15.0,20.0], [21.0,28.0], [32.0,36.0],[41.0,44.0]]
x= []
print "in between"
for t in range(len(q)-1):
a,b=q[t][1],q[t+1][0]
x.append([a,b])
for i in x:
print i
Run Code Online (Sandbox Code Playgroud)
输出:
[4.0, 10.0]
[12.0, 15.0]
[20.0, 21.0]
[28.0, 32.0]
[36.0, 41.0]
Run Code Online (Sandbox Code Playgroud)
更新:我想在我的^输出中追加两个段.
上下文:这些段是时间戳.
假设段没有从零开始,而是从3.0开始,
q= [[3.0,4.0], [10.0,12.0], [15.0,20.0], [21.0,28.0], [32.0,36.0],[41.0,44.0]]
文件以50.0结束.
我原来的输出,我想补充的区域:[0.0,3]和[44.0,50.0]这样我可以沉默了这些地区了.
为此,我简单地做了:
import numpy
speaker_segments= [[3.0,4.0], [10.0,12.0], [15.0,20.0], [21.0,28.0], [32.0,36.0],[41.0,44.0]]
segments_to_silence = []
starting= 0.0 …Run Code Online (Sandbox Code Playgroud) python ×2
r ×2
coercion ×1
dataframe ×1
pip ×1
python-2.7 ×1
text-mining ×1
twitter ×1
vector ×1