我想在每个组中找到lead()和lag()元素,但是有一些错误的结果.
例如,数据是这样的:
library(dplyr)
df = data.frame(name=rep(c('Al','Jen'),3),
score=rep(c(100, 80, 60),2))
df
Run Code Online (Sandbox Code Playgroud)
数据:
name score
1 Al 100
2 Jen 80
3 Al 60
4 Jen 100
5 Al 80
6 Jen 60
Run Code Online (Sandbox Code Playgroud)
现在我试着找出每个人的lead()和lag()得分.如果我使用arrange()对其进行排序,我可以得到正确的答案:
df %>%
arrange(name) %>%
group_by(name) %>%
mutate(next.score = lead(score),
before.score = lag(score) )
Run Code Online (Sandbox Code Playgroud)
OUTPUT1:
Source: local data frame [6 x 4]
Groups: name
name score next.score before.score
1 Al 100 60 NA
2 Al 60 80 100
3 Al 80 NA 60
4 Jen 80 100 NA
5 …Run Code Online (Sandbox Code Playgroud) 我selenium用来点击我想要的网页,然后使用解析网页Beautiful Soup.
有人已经展示了如何获取元素的内部HTMLSelenium WebDriver.有没有办法获取整个页面的HTML?谢谢
示例代码Python
(基于上面的帖子,语言似乎并不重要):
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from bs4 import BeautifulSoup
url = 'http://www.google.com'
driver = webdriver.Firefox()
driver.get(url)
the_html = driver---somehow----.get_attribute('innerHTML')
bs = BeautifulSoup(the_html, 'html.parser')
Run Code Online (Sandbox Code Playgroud) 我想我正在使用 Visual Studio 2017 并编写了一个 SSIS 包。现在我安装了visual studio 2019,无法打开解决方案文件。错误:
不支持 此版本的 Visual Studio 无法打开以下项目。可能未安装项目类型或此版本的 Visual Studio 可能不支持它们。有关启用这些项目类型或以其他方式迁移资产的更多信息,请参阅单击“确定”后显示的“迁移报告”中的详细信息。- ABC, "C:\Users\XYZ\ABC.dtproj"
需要的非功能性更改 Visual Studio 将自动对以下项目进行非功能性更改,以使它们能够在 Visual Studio 2015、Visual Studio 2013、Visual Studio 2012 和 Visual Studio 2010 SP1 中打开。项目行为不会受到影响。- ABC_SSIS, "C:\Users\XYZ\ABC_SSIS.sln"
我试过“右键单击项目并重新加载” - 没有用。
嗨所以我在a上应用find_all beautifulsoup object,并找到一些东西,这是一个bs4.element.ResultSet object或一个list.
我想在那里进一步做find_all,但是不允许这样做 bs4.element.ResultSet object.我可以循环遍历bs4.element.ResultSet objectfind_all的每个元素.但是我可以避免循环并将其转换回来beautifulsoup object吗?
请参阅代码了解详情.谢谢
html_1 = """
<table>
<thead>
<tr class="myClass">
<th>A</th>
<th>B</th>
<th>C</th>
<th>D</th>
</tr>
</thead>
</table>
"""
soup = BeautifulSoup(html_1, 'html.parser')
type(soup) #bs4.BeautifulSoup
# do find_all on beautifulsoup object
th_all = soup.find_all('th')
# the result is of type bs4.element.ResultSet or similarly list
type(th_all) #bs4.element.ResultSet
type(th_all[0:1]) #list
# now I want to further do find_all
th_all.find_all(text='A') #not work
# can I avoid this …Run Code Online (Sandbox Code Playgroud) GitLab 不会为我呈现 HTML,而只是显示源代码:
背景:我使用 sphinx 生成 HTML 并尝试在 GitLab 上展示文档。
我查看了其他项目的存储库,例如pandas, sphinx. 它们.rts在存储库中只有文件,而不是 HTML 文件。我猜他们会为他们的网站生成 HTML,但不会上传到 Git。
我没有网站,想在 GitLab 上展示文档。有没有办法做到这一点?或者我是否必须生成其他格式(HTML 除外,例如 PDF)?
我在笔记本电脑上测试我的应用程序,然后将其部署到shinyapps服务器.在部署之前,我需要删除设置路径的语句,例如,
setwd('/Users/MrY/OneDrive/Data')
Run Code Online (Sandbox Code Playgroud)
有没有一种方法代码可以找出它是在本地运行还是在服务器上运行,所以它会像:
if (isLocal()) {
setwd('/Users/MrY/OneDrive/Data')
}
Run Code Online (Sandbox Code Playgroud)
一个简单的示例代码(如果setwd未删除,它将在服务器上失败):
server.R
library(shiny)
setwd('/Users/Yuji/OneDrive/Data/TownState')
data = 'data1.csv' # to test, using an empty .csv file
shinyServer(function(input, output) {
})
Run Code Online (Sandbox Code Playgroud)
ui.R
library(shiny)
shinyUI(pageWithSidebar(
headerPanel("Click the button"),
sidebarPanel(
actionButton("goButton", "Go!")
),
mainPanel(
)
))
Run Code Online (Sandbox Code Playgroud) 我试过了
download.file('https://www.dropbox.com/s/r3asyvybozbizrm/Himalayas.jpg',
destfile="1.jpg",
method="auto")
Run Code Online (Sandbox Code Playgroud)
但它返回该页面的HTML源代码.
还试了一下rdrop
library(rdrop2)
# please put in your key/secret
drop_auth(new_usesr = FALSE, key=key, secret=secret, cache=T)
Run Code Online (Sandbox Code Playgroud)
弹出网站报道:
Invalid redirect_uri: "http://localhost:1410": It must exactly match one of the redirect URIs you've pre-configured for your app (including the path).
Run Code Online (Sandbox Code Playgroud)
我不太了解URI的事情.有人可以推荐一些文件来阅读....
我阅读了一些帖子,但大多数都讨论了如何从excel文件中读取数据.
repmis仅用于阅读excel文件...
library(repmis)
repmis::source_DropboxData("test.csv",
"tcppj30pkluf5ko",
sep = ",",
header = F)
Run Code Online (Sandbox Code Playgroud)
也试过了
library(RCurl)
url='https://www.dropbox.com/s/tcppj30pkluf5ko/test.csv'
x = getURL(url)
read.csv(textConnection(x))
Run Code Online (Sandbox Code Playgroud)
它不起作用......
任何帮助和讨论都表示赞赏.谢谢!
嗨〜我看到了一些关于此的讨论,但似乎没有多少答案.所以我在城市地图上绘制密度/热图.
df = data.frame(lon=rnorm(1000, mean=-87.62, sd=0.01),
lat=rnorm(1000, mean=41.88, sd=0.01))
map = get_googlemap('chicago', zoom=14, color='bw')
ggmap(map, extent='device') +
stat_density2d(
aes(x=lon, y=lat, fill=..level.., alpha =..level..),
size = 2, bins = 4,
data = df,
geom = "polygon"
) +
scale_fill_gradient(low='green', high='red') +
scale_alpha(guide=FALSE)
Run Code Online (Sandbox Code Playgroud)
它描绘得很好,但显示:
Warning message:
Removed 96 rows containing non-finite values (stat_density2d).
Run Code Online (Sandbox Code Playgroud)
使用真实的城市犯罪数据,它实际上报告删除了大多数行.因此,我担心情节可能并不反映真实的分布情况.
这是什么意思?我应该担心情节不能反映数据吗?谢谢!
我正在做数据清理.我在Dplyr中使用mutate很多,因为它逐步生成新的列,我可以很容易地看到它是如何进行的.
以下是我遇到此错误的两个示例
Error: incompatible size (%d), expecting %d (the group size) or 1
Run Code Online (Sandbox Code Playgroud)
示例1:从邮政编码获取城镇名称.数据就像这样:
Zip
1 02345
2 02201
Run Code Online (Sandbox Code Playgroud)
我注意到当数据中包含NA时,它不起作用.
没有NA它有效:
library(dplyr)
library(zipcode)
data(zipcode)
test = data.frame(Zip=c('02345','02201'),stringsAsFactors=FALSE)
test %>%
rowwise() %>%
mutate( Town1 = zipcode[zipcode$zip==na.omit(Zip),'city'] )
Run Code Online (Sandbox Code Playgroud)
导致
Source: local data frame [2 x 2]
Groups: <by row>
Zip Town1
1 02345 Manomet
2 02201 Boston
Run Code Online (Sandbox Code Playgroud)
使用NA它不起作用:
library(dplyr)
library(zipcode)
data(zipcode)
test = data.frame(Zip=c('02345','02201',NA),stringsAsFactors=FALSE)
test %>%
rowwise() %>%
mutate( Town1 = zipcode[zipcode$zip==na.omit(Zip),'city'] )
Run Code Online (Sandbox Code Playgroud)
导致
Error: incompatible size (%d), expecting %d (the group …Run Code Online (Sandbox Code Playgroud) 我知道我可以使用查看R对象的大小object.size,但是如何在Rstudio中检查R的总内存使用情况,R中的内存组成?
我看到了这篇文章,但没有找到菜单Memory usage下的按钮Tools.
我正在使用Rstudio V 0.99.896和RV 3.2.5.
具体情况:
我在看Windows Task ManagerR时工作,我注意到当我read.table将~~ 2G数据输入R 时,计算机的内存使用量增加了~7G .