如何找到li具有特定类名而不是其他类名的标签?例如:
...
<li> no wanted </li>
<li class="a"> not his one </li>
<li class="a z"> neither this one </li>
<li class="b z"> neither this one </li>
<li class="c z"> neither this one </li>
...
<li class="z"> I WANT THIS ONLY ONE</li>
...
Run Code Online (Sandbox Code Playgroud)
编码:
bs4.find_all ('li', class_='z')
返回几个条目,其中有一个"z"和另一个类名。
如何"z"单独找到带有类名的条目?
我需要使用R得到大数据集的所有列的平均值,按2个变量分组.
让我们尝试使用mtcars:
library(dplyr)
g_mtcars <- group_by(mtcars, cyl, gear)
summarise(g_mtcars, mean (hp))
# Source: local data frame [8 x 3]
# Groups: cyl [?]
#
# cyl gear `mean(hp)`
# <dbl> <dbl> <dbl>
# 1 4 3 97.0000
# 2 4 4 76.0000
# 3 4 5 102.0000
# 4 6 3 107.5000
# 5 6 4 116.5000
# 6 6 5 175.0000
# 7 8 3 194.1667
# 8 8 5 299.5000
Run Code Online (Sandbox Code Playgroud)
它适用于"hp",但我需要获得mtcars的每个其他列的平均值(除了"cyl"和"gear"组成一个组).数据集很大,有几列.手工打字,就像这样:summarise(g_mtcars, mean (hp), mean(drat), mean (wt),...)它不是实用的.
我设法创建一个具有1个键和2个值的查找表:
public static Map<String, Map.Entry<String, String>> myMap;
myMap= new HashMap<String, Map.Entry<String, String>>();
myMap.put("key 1", new AbstractMap.SimpleEntry<String, String>(" value 1.1", "value 1.2"));
myMap.put("key 2", new AbstractMap.SimpleEntry<String, String>(" value 2.1", "value 2.2"));
// and so on...
// retrieve the key, values
Map.Entry<String, String> pair;
for (String key : myMap.keySet() ) {
pair = oidMap.get(key);
value1= pair.getKey();
value2= pair.getValue();
///use the key, value1, value2 as needed
}
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试将其扩展到4个值时,我遇到了很多错误,我发现Entry仅限于2个值!
public static Map<String, Map.Entry<String, String, Float, String>> myMap;
myMap= new HashMap<String, Map.Entry<String, String, Float, String>>(); …Run Code Online (Sandbox Code Playgroud)