我知道这里有几个类似的问题,但是似乎没有一个问题可以解决我遇到的确切问题。
set.seed(4)
df = data.frame(
Key = c("A", "B", "A", "D", "A"),
Val1 = rnorm(5),
Val2 = runif(5),
Val3 = 1:5
)
Run Code Online (Sandbox Code Playgroud)
我想将其中Key ==“ A”的行的value列的值清零。通过a引用列名grep:
cols = grep("Val", names(df), value = TRUE)
Run Code Online (Sandbox Code Playgroud)
通常,在这种情况下,要实现我想要的功能,我将使用data.table以下命令:
library(data.table)
df = as.data.table(df)
df[Key == "A", (cols) := 0]
Run Code Online (Sandbox Code Playgroud)
所需的输出是这样的:
Key Val1 Val2 Val3
1 A 0.000000 0.00000000 0
2 B -1.383814 0.55925762 2
3 A 0.000000 0.00000000 0
4 D 1.437151 0.05632773 4
5 A 0.000000 0.00000000 0
Run Code Online (Sandbox Code Playgroud)
但是这一次我需要dplyr在每个人都在使用的团队项目中使用它。我刚刚提供的数据是说明性的,我的真实数据是> …
我正在尝试使用 python 的请求模块来抓取在网站上生成图表的数据。
我的代码目前如下所示:
# load modules
import os
import json
import requests as r
# url to send the call to
postURL = <insert website>
# utiliz get to pull cookie data
cookie_intel = r.get(postURL, verify = False)
# get cookies
search_cookies = cookie_intel.cookies
#### Request Information ####
# API request data
post_data = <insert request json>
# header information
headers = {"user-agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"}
# results
results_post = r.post(postURL, …Run Code Online (Sandbox Code Playgroud)