我使用Python 3和请求模块/库来查询REST服务.
似乎默认情况下请求urllib.parse.quote_plus()用于urlencoding,即空格转换为+.
但是我查询的REST服务误解了这一点and.所以我需要将空格编码为%20,即urllib.parse.quote()改为使用.
有没有一种简单的方法来处理请求?我在文档中找不到任何选项.
我尝试对以下数据帧使用 R 进行 t 检验。
df <- structure(list(freq = c(9, 11, 14, 12, 10, 9, 16, 10, 11, 15,
13, 12, 12, 13, 13, 9, 16, 14, 12, 15, 16, 10, 11, 13, 14, 14,
14, 16, 8, 10, 14, 14, 11, 11, 11, 11, 13, 7, 12, 13, 14, 11,
11, 13, 10, 14, 10, 10, 12, 8, 9, 12, 14, 11, 12, 12, 14, 14,
14, 15, 12, 13, 14, 8, 9, 11, 10, 14, 12, 12, 9, …Run Code Online (Sandbox Code Playgroud) 我似乎错过了ggplot2如何工作的变化.我有一个统计教科书的例子(A. Field(2012),使用R,p.593发现统计数据),我确信它可以工作,但现在不再产生分组数据之间的连接线.
这是示例数据:
participant<-gl(20, 9, labels = c("P01", "P02", "P03", "P04", "P05", "P06", "P07", "P08", "P09", "P10", "P11", "P12", "P13", "P14", "P15", "P16", "P17", "P18", "P19", "P20" ))
drink<-gl(3, 3, 180, labels = c("Beer", "Wine", "Water"))
imagery<-gl(3, 1, 180, labels = c("Positive", "Negative", "Neutral"))
groups<-gl(9, 1, 180, labels = c("beerpos", "beerneg", "beerneut", "winepos", "wineneg", "wineneut", "waterpos", "waterneg", "waterneut"))
attitude<-c(1, 6, 5, 38, -5, 4, 10, -14, -2, 26, 27, 27, 23, -15, 14, 21, -6, 0, 1, -19, -10, 28, …Run Code Online (Sandbox Code Playgroud) 我想用我的脚本中的新python字符串格式化语法替换旧的字符串格式化行为,但是当我处理浮点数时如何避免舍入?
旧版本
print ('%02d:%02d:%02d' % (0.0,0.9,67.5))
Run Code Online (Sandbox Code Playgroud)
产量 00:00:67
而我(显然是错误的)翻译成新语法
print ('{0:0>2.0f}:{1:0>2.0f}:{2:0>2.0f}'.format(0.0,0.9,67.5))
Run Code Online (Sandbox Code Playgroud)
收益率00:01:68.
如何避免在这里舍入并使用新格式语法获取旧输出?
我认为这与这篇文章类似但不完全一样,我无法理解它.
所以,我目前有一个(非常奇怪的)pandas数据帧,每个单元格中有一个列表,如下所示:
>>> data = pd.DataFrame({'myid' : ['1', '2', '3'],
'num' : [['1', '2', '3'], ['1', '2'], []],
'text' : [['aa', 'bb', 'cc'], ['cc', 'dd'],
[]]}).set_index('myid')
>>> print(data)
num text
myid
1 [1, 2, 3] [aa, bb, cc]
2 [1, 2] [cc, dd]
3 [] []
Run Code Online (Sandbox Code Playgroud)
我想实现这个目标:
myid num text
0 1 1 aa
0 1 2 bb
0 1 3 cc
1 2 1 cc
1 2 2 dd
2 3
Run Code Online (Sandbox Code Playgroud)
我如何到达那里?
如果我有以下列表
vowels = ["a","e","i","o","u"]
Run Code Online (Sandbox Code Playgroud)
和另一个清单
words = ["happiness", "yellow"]
Run Code Online (Sandbox Code Playgroud)
我如何计算每个单词中的元音数量,即幸福= 3,黄色= 2?
我有以下数据集:
subj <- c(rep(11,3),rep(12,3),rep(14,3),rep(15,3),rep(17,3),rep(18,3),rep(20,3))
group <- c(rep("u",3),rep("t",6),rep("u",6),rep("t",6))
time <- rep(1:3,7)
mean <- c(0.7352941, 0.8059701, 0.8823529, 0.9264706, 0.9852941, 0.9558824, 0.7941176, 0.8676471, 0.7910448, 0.7058824, 0.8382353, 0.7941176, 0.9411765, 0.9558824, 0.9852941, 0.7647059, 0.8088235, 0.7968750, 0.8088235, 0.8500000, 0.8412698)
df <- data.frame(subj,group,time,mean)
df$subj <- as.factor(df$subj)
df$time <- as.factor(df$time)
Run Code Online (Sandbox Code Playgroud)
现在我用ggplot2创建一个条形图:
library(ggplot2)
qplot(x=subj, y=mean*100, fill=time, data=df, geom="bar",stat="identity",position="dodge") +
facet_wrap(~ group)
Run Code Online (Sandbox Code Playgroud)

如何使其不显示每个方面中不存在的x轴标签?如何在每个subj之间获得相等的距离(即摆脱更大的间隙)?
我想让 Ansible 读出内核中的用户命名空间是否被激活 (CentOS)。当我运行时,相应的值是可见的
- debug:
msg: "{{ ansible_cmdline }}"
Run Code Online (Sandbox Code Playgroud)
这给了我输出:
"msg": {
"BOOT_IMAGE": "/vmlinuz-...",
"LANG": "...",
"crashkernel": "...",
"namespace.unpriv_enable": "...",
"quiet": ...,
"rd.lvm.lv": "...",
"rhgb": ...,
"ro": ...,
"root": "...",
"user_namespace.enable": "1"
}
Run Code Online (Sandbox Code Playgroud)
但是,我没有成功直接查询子项:
- debug:
msg: "{{ ansible_cmdline.user_namespace.enable }}"
Run Code Online (Sandbox Code Playgroud)
Ansible 将 解释.enable为进一步的子项:
The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'user_namespace'
如何访问密钥"user_namespace.enable"?
我有以下数据集:
cond <- gl(15,1,labels=c("a1","a2","a3","a4","a5","b1","b2","b3","b4","b5","c1","c2","c3","c4","c5"))
pos <-c(rep("a",5),rep("b",5),rep("c",5))
mean <- c(3.202634, 3.819009, 3.287785, 4.531127, 3.093865, 3.360535, 4.084791, 3.886960, 3.297692, 4.281323, 2.418745, 3.759699, 3.553860, 4.812989, 1.606597)
hd <- c(TRUE, FALSE, TRUE, FALSE, TRUE, TRUE, FALSE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE, FALSE, TRUE)
df <- data.frame(cond,pos,mean,hd)
Run Code Online (Sandbox Code Playgroud)
......并生成了这个情节
library(ggplot2)
b <- ggplot(df, aes(x=cond, y = mean, fill=pos)) + labs(x = "X", y="Y", fill=NULL)
c <- b + geom_bar(stat = "identity", position="dodge") + theme(text = element_text(size=18), axis.text.x = element_text(colour="black", size = 14)) + scale_fill_brewer(palette="Set1")
my_theme …Run Code Online (Sandbox Code Playgroud) 在Postgres 9.5.1中,以下命令有效:
select regexp_replace('JamesBond007','\d+','');
Run Code Online (Sandbox Code Playgroud)
输出:
JamesBond
Run Code Online (Sandbox Code Playgroud)
然而,星号似乎不起作用:
select regexp_replace('JamesBond007','\d*','');
Run Code Online (Sandbox Code Playgroud)
它产生:
JamesBond007
Run Code Online (Sandbox Code Playgroud)
当我把一些东西作为替换字符串时,会发生更奇怪的事情:
select regexp_replace('JamesBond007','\d+','008');
Run Code Online (Sandbox Code Playgroud)
结果是:
JamesBond008
Run Code Online (Sandbox Code Playgroud)
而
select regexp_replace('JamesBond007','\d*','008');
Run Code Online (Sandbox Code Playgroud)
让我回来:
008JamesBond007
Run Code Online (Sandbox Code Playgroud)
Postgres文档说*=原子的0或更多匹配的序列.那么这里发生了什么?(在Oracle中注意以上所有工作如预期的那样)
假设我在python中有以下列表:
a = ['a','b','c','d','e','f','g','h','i','j']
Run Code Online (Sandbox Code Playgroud)
如何分发如下列表:
['a','f']
['b','g']
['c','h']
['d','i']
['e','j']
Run Code Online (Sandbox Code Playgroud)
如果我有一个不等长度列表并将"多余"项目放入单独的列表中,我该如何实现这一目标?
我希望能够以指示的方式将原始列表的元素分配到n个部分.
因此,如果n = 3,那将是:
['a','d','g']
['b','e','h']
['c','f','i']
Run Code Online (Sandbox Code Playgroud)
和单独列表中的"多余"元素
['j']
Run Code Online (Sandbox Code Playgroud) python ×4
r ×4
ggplot2 ×3
list ×2
ansible ×1
axis-labels ×1
dataframe ×1
facet-wrap ×1
format ×1
pandas ×1
plot ×1
postgresql ×1
python-2.7 ×1
python-3.x ×1
quantifiers ×1
regex ×1
reshape ×1
string ×1
urlencode ×1