使用read.csv,我从 .csv 文件中读取了一个数据框,其中的数据排列如下:
team1 team2 team3
Andy Alice Karen
Bob Belle Kyle
Chad Carol
Diana
Run Code Online (Sandbox Code Playgroud)
team <- read.csv("team.csv")
Run Code Online (Sandbox Code Playgroud)
数据框属于因子类,尺寸为 4x3。对于team1和team3列,额外的空行用 来显示""。我想使用转换将列提取为向量as.character。但是如何缩短这个向量并排除""元素呢?例如:
team1_list <- as.character(team$team1)包括尾随""元素。我只想得到向量("Andy", "Bob", "Chad")而不是("Andy", "Bob", "Chad", "")
我在 AWS EC2 CentOS 7 上流式传输 Kafka。我的会话管理器空闲超时设置为 60 分钟。然而,在运行的时间远低于此值后,终端被冻结,并显示My session has been terminated。当然,Kafka 流也中断了。
当我尝试使用新终端重新启动新会话时,出现此错误弹出窗口
Your session has been terminated for the following reasons: Plugin with name Standard_Stream not found. Step name: Standard_Stream
Run Code Online (Sandbox Code Playgroud)
我仍然无法重新启动终端。
这个错误是什么意思以及如何解决它?谢谢。
我有一个包含多个级别的 XML。每个级别都可能附加有命名空间。我想要find一个我知道其名称但不知道其名称空间的特定元素。例如:
my_file.xml
<?xml version="1.0" encoding="UTF-8"?>
<data xmlns="aaa:bbb:ccc:ddd:eee">
<country name="Liechtenstein" xmlns="aaa:bbb:ccc:liechtenstein:eee">
<rank updated="yes">2</rank>
<year>2008</year>
<gdppc>141100</gdppc>
<neighbor name="Austria" direction="E"/>
<neighbor name="Switzerland" direction="W"/>
</country>
<country name="Singapore" xmlns="aaa:bbb:ccc:singapore:eee">
<continent>Asia</continent>
<holidays>
<christmas>Yes</christmas>
</holidays>
<rank updated="yes">5</rank>
<year>2011</year>
<gdppc>59900</gdppc>
<neighbor name="Malaysia" direction="N"/>
</country>
<country name="Panama" xmlns="aaa:bbb:ccc:panama:eee">
<rank updated="yes">69</rank>
<year>2011</year>
<gdppc>13600</gdppc>
<neighbor name="Costa Rica" direction="W"/>
<neighbor name="Colombia" direction="E"/>
</country>
</data>
Run Code Online (Sandbox Code Playgroud)
import lxml.etree as etree
tree = etree.parse('my_file.xml')
root = tree.getroot()
cntry_node = root.find('.//country')
Run Code Online (Sandbox Code Playgroud)
上面的内容find不会返回任何内容cntry_node。在我的真实数据中,层次比这个例子更深。lxml 文档讨论了命名空间。当我这样做时:
root.nsmap
Run Code Online (Sandbox Code Playgroud)
我看到这个:
{None: 'aaa:bbb:ccc:ddd:eee'}
Run Code Online (Sandbox Code Playgroud)
如果有人可以解释如何访问完整内容nsmap …
假设我有一个按偏好降序排列的列表:
person_choice = ['amy', 'bob', 'chad', 'dan', 'emily']
Run Code Online (Sandbox Code Playgroud)
意思是,amy优先于bob,优先于谁chad等等。
我还有几个这样的列表(名称没有特定的顺序和列表长度出现):
group1 = ['joyce', 'amy', 'emily', 'karen', 'rebecca']
group2 = ['chad', 'kyle', 'michael', 'neo', 'bob']
...
Run Code Online (Sandbox Code Playgroud)
在每个group1和中group2,我想选择此列表中具有person_choice最高偏好的人。所以,预期的输出是这样的:
group1_choice = 'amy'
group2_choice = 'bob'
Run Code Online (Sandbox Code Playgroud)
假设对于每个groupX,至少有一个人出现在person_choice,Python 中是否有一个单行代码可以在没有复杂for循环的情况下执行此操作?
我有这个功能,旨在每次单击按钮时在按钮的两种预定义颜色之间切换背景:
const showAvailButtonClicked = (targetButton, clickedColor, unClickedColor) => {
let clickedElement = document.getElementById(targetButton)
let currColor = clickedElement.style.backgroundColor
if (currColor == clickedColor) {
clickedElement.style.backgroundColor = unClickedColor
} else {
alert("Current color:" + currColor)
clickedElement.style.backgroundColor = clickedColor
}
}
let targetButton = document.getElementById("testbutton")
targetButton.addEventListener("click", () => {
showAvailButtonClicked("testbutton","#ba0202", "#0f2e0c")
})Run Code Online (Sandbox Code Playgroud)
#testbutton {
background-color: #0f2e0c;
}Run Code Online (Sandbox Code Playgroud)
<button id="testbutton">Toggle</button>Run Code Online (Sandbox Code Playgroud)
我在上面这个简单的代码中遇到了两个问题:
1 - 按钮以这种颜色开始unClickedColor = #0f2e0c。但是,第一次单击时,警报不会记录任何颜色。IE。Current color:仅显示警报消息。
2 - 在第二次及后续单击中,该行中注册的颜色let currColor = clickedElement.style.backgroundColor给出 RGB 格式rgb(r, g, b)。如何强制将其转换为十六进制格式以便进行颜色比较?谢谢。