我正在使用ruby,我得到了一个带有一些ruby程序的zip文件,它说:在文件夹中,运行bundle install以安装所需的软件包.
当我在终端中运行命令时,它说bundle command not found.
有人可以给我详细说明如何解决这个问题吗?
我有一个出租车数据的数据框,有两列,如下所示:
Neighborhood Borough Time
Midtown Manhattan X
Melrose Bronx Y
Grant City Staten Island Z
Midtown Manhattan A
Lincoln Square Manhattan B
Run Code Online (Sandbox Code Playgroud)
基本上,每行代表该行政区附近的出租车.现在,我想在每个行政区找到前5个街区,拥有最多的皮卡.我试过这个:
df['Neighborhood'].groupby(df['Borough']).value_counts()
Run Code Online (Sandbox Code Playgroud)
这给了我这样的东西:
borough
Bronx High Bridge 3424
Mott Haven 2515
Concourse Village 1443
Port Morris 1153
Melrose 492
North Riverdale 463
Eastchester 434
Concourse 395
Fordham 252
Wakefield 214
Kingsbridge 212
Mount Hope 200
Parkchester 191
......
Staten Island Castleton Corners 4
Dongan Hills 4
Eltingville 4
Graniteville 4
Great Kills 4
Castleton 3
Woodrow 1
Run Code Online (Sandbox Code Playgroud)
如何过滤它以便我只获得前5个?我知道有几个问题有类似的标题,但它们对我的情况没有帮助.
假设我有这样的代码
# Install devtools if needed
if(!require(devtools)) install.packages("devtools")
# view rawif-devtools.R hosted with ? by GitHub
# Install leaflet package
if(!require(leaflet)) install_github("rstudio/leaflet")
library("leaflet")
mymap <- leaflet()
mymap <- addTiles(mymap)
mymap
Run Code Online (Sandbox Code Playgroud)
这会在Chrome中打开,文件路径如下:
file:///var/folders/8x/v2tk5zy51x51jx9jbp0m29qr0000gn/T/RtmpQaeu1E/viewhtmlf74547061f7d/index.html.
Run Code Online (Sandbox Code Playgroud)
假设我想将此内容发布到我的博客中.我究竟如何访问这个html文件?有没有办法设置保存到哪里?我以为它会被保存到工作目录但事实并非如此.我想我可以通过终端访问它,但我希望有一个更简单的方法.
我有一个具有不同名称的列:
X <- c("Ashley, Tremond WILLIAMS, Carla", "Claire, Daron", "Luw, Douglas CANSLER, Stephan")
Run Code Online (Sandbox Code Playgroud)
在第二个空格之后,它开始第二个人的名字。例如,Ashley、Tremond 是一个人,WILLIAMS、Carla 是另一个人。
我努力了:
strsplit(X, "\\,\\s|\\,|\\s")
Run Code Online (Sandbox Code Playgroud)
但它除以所有空格,所以我得到:
strsplit(X, "\\,\\s|\\,|\\s")
[[1]]
[1] "Ashley" "Tremond" "WILLIAMS" "Carla"
[[2]]
[1] "Claire" "Daron"
[[3]]
[1] "Luw" "Douglas" "CANSLER" "Stephan"
Run Code Online (Sandbox Code Playgroud)
我怎样才能只在第一个空格之后分开,这样我就明白了?:
[1] "Ashley, Tremond" "WILLIAMS, Carla"
[[2]]
[1] "Claire, Daron"
[[3]]
[1] "Luw, Douglas" "CANSLER, Stephan"
Run Code Online (Sandbox Code Playgroud)
预先感谢您的所有帮助
我想在这里找到一个危险数据集的wordcloud:https://www.reddit.com/r/datasets/comments/1uyd0t/200000_jeopardy_questions_in_a_json_file/
我的代码如下:
library(tm)
library(SnowballC)
library(wordcloud)
jeopQ <- read.csv('JEOPARDY_CSV.csv', stringsAsFactors = FALSE)
jeopCorpus <- Corpus(VectorSource(jeopQ$Question))
jeopCorpus <- tm_map(jeopCorpus, PlainTextDocument)
jeopCorpus <- tm_map(jeopCorpus, removePunctuation)
jeopCorpus <- tm_map(jeopCorpus, removeWords, c('the', 'this', stopwords('english')))
jeopCorpus <- tm_map(jeopCorpus, stemDocument)
wordcloud(jeopCorpus, max.words = 100, random.order = FALSE)
Run Code Online (Sandbox Code Playgroud)
单词'the'和'this'仍出现在wordcloud中.为什么会发生这种情况,我该如何解决?
我有一个像这样的位置列的数据集(41.797634883,-87.708426986).我想把它分成纬度和经度.我尝试使用tidyr包中的单独方法
library(dplyr)
library(tidyr)
df <- data.frame(x = c('(4, 9)', '(9, 10)', '(20, 100)', '(100, 200)'))
df %>% separate(x, c('Latitude', 'Longitude'))
Run Code Online (Sandbox Code Playgroud)
但是我收到了这个错误
Error: Values not split into 2 pieces at 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
我正在尝试在 R 中复制以下 Python 代码的输出:
import hashlib
x = hashlib.sha256()
x.update("asdf".encode("utf8"))
print(x.digest())
# b'\xf0\xe4\xc2\xf7lX\x91n\xc2X\xf2F\x85\x1b\xea\t\x1d\x14\xd4$z/\xc3\xe1\x86\x94F\x1b\x18\x16\xe1;'
Run Code Online (Sandbox Code Playgroud)
这是我的 R 代码:
library(digest)
digest("asdf", algo="sha256", serialize=FALSE)
# "f0e4c2f76c58916ec258f246851bea091d14d4247a2fc3e18694461b1816e13b"
Run Code Online (Sandbox Code Playgroud)
我可以通过使用x.hexdigest()而不是x.digest(). 如何x.digest()在我的 R 代码中获取输出?
假设我有两个数据帧:
import string
import pandas as pd
d = {'one': pd.Series(range(26), index = list(string.ascii_lowercase)),
'two': pd.Series([1., 2., 3., 4.], index = ['a', 'b', 'c', 'd'])}
df = pd.DataFrame(d)
d2 = {'one': pd.Series(range(10), index = range(11, 21))}
df2 = pd.DataFrame(d2)
Run Code Online (Sandbox Code Playgroud)
现在,我有一个索引列表:
np.random.seed(12)
i = np.random.choice(np.arange(11, 21), size = 26)
Run Code Online (Sandbox Code Playgroud)
现在,我想加入df2与df1基于i.
df['new_col'] = df2['one'][i]
Run Code Online (Sandbox Code Playgroud)
但是我得到了上面提到的错误.解决这个问题的一种方法是i直接添加df1,并创建一个名为iin 的列df2来表示index,然后执行a merge但看起来非常低效.有一个更好的方法吗?
我知道有几个问题有相同的标题,但没有一个对我的案例有任何帮助.
我正在尝试分析一个大数据集.其中一列是starttime列,其原始类是character.
我使用了这个命令:
data$starttime = strptime(data$starttime, "%Y-%m-%d %H:%M:%S).
Run Code Online (Sandbox Code Playgroud)
我收到此错误消息:
**Error in `[<-.data.table`(x, j = name, value = value) :
(list) object cannot be coerced to type 'double'**
Run Code Online (Sandbox Code Playgroud)
另外:警告信息:
**In `[<-.data.table`(x, j = name, value = value) :
Supplied 11 items to be assigned to 13118401 items of column 'startime' (recycled leaving remainder of 10 items).**
Run Code Online (Sandbox Code Playgroud)
我也尝试了as.Date()和ymd_hms()函数,但他们给出了同样的错误.这究竟是什么意思,我该如何解决?
我刚刚学习了Ruby,我正在做一些基本的练习问题来熟悉这门语言.我刚刚遇到这个问题:"编写一个采用数组数组的方法.如果数组中的一对数字总和为零,则返回这两个数字的位置.如果没有数字对总和为零,则返回nil. "
这是我的代码:
def two_sum(nums)
i = 0
j = 0
while i < nums.length
while j < nums.length
if nums[i] + nums[j] == 0
return [i, j]
end
j+= 1
end
i += 1
end
return nil
end
Run Code Online (Sandbox Code Playgroud)
它每次都返回nil.它出什么问题了?