What is the quickest/best way to change a large number of columns to numeric from factor?
I used the following code but it appears to have re-ordered my data.
> head(stats[,1:2])
rk team
1 1 Washington Capitals*
2 2 San Jose Sharks*
3 3 Chicago Blackhawks*
4 4 Phoenix Coyotes*
5 5 New Jersey Devils*
6 6 Vancouver Canucks*
for(i in c(1,3:ncol(stats))) {
stats[,i] <- as.numeric(stats[,i])
}
> head(stats[,1:2])
rk team
1 2 Washington Capitals*
2 13 San Jose Sharks* …Run Code Online (Sandbox Code Playgroud) 随着journalctl,就可以删除旧的日志,通过指定的最大磁盘空间,他们可以使用,也可以有最大年龄,或(使用选件单独的日志文件的最大数量--vacuum-size,--vacuum-time或--vacuum-files).
有没有办法将此删除限制在特定的系统单元?
journalctl -u <unit> --vacuum-time=2d似乎没有按预期工作:根据文档,-u只有在显示日志时才有效.
假设我有一个DataFrame像这样生成的熊猫:
df = pd.DataFrame(columns=['x_value', 'y_value'])
for x in [1.0, 3.0, 9.0]:
for _ in range(1000):
df = df.append({'x_value':x, 'y_value':np.random.random()}, ignore_index=True)
Run Code Online (Sandbox Code Playgroud)
结果看起来像这样:
In: df.head()
Out:
x_value y_value
0 1.0 0.616052
1 3.0 1.406715
2 9.0 8.774720
3 1.0 0.810729
4 3.0 1.309627
Run Code Online (Sandbox Code Playgroud)
使用 seaborn 生成箱线图提供了以下结果:
[In] sns.boxplot(x='x_value', y='y_value', data=df)
[Out]
Run Code Online (Sandbox Code Playgroud)
我想要的是生成一组间隔开的箱线图,就好像 x 轴值被视为数字,而不仅仅是标签。
这可能吗?如果箱线图不能做到这一点,我是否只是在查看错误类型的图表来传达有关我的数据分散的信息?
在交互使用时bluetoothctl,它不断报告来自邻居设备的 RSSI 变化。大多数时候这很烦人,因为在将笔记本电脑连接到蓝牙鼠标时,我不关心同事 iMac 的 RSSI:
$ bluetoothctl
Agent registered
[CHG] Device 2C:xx:xx:xx:xx:B6 RSSI: -79
[CHG] Device 2C:xx:xx:xx:xx:B6 RSSI: -79
[CHG] Device 2C:xx:xx:xx:xx:B6 RSSI: -82
[CHG] Device 2C:xx:xx:xx:xx:B6 RSSI: -81
[CHG] Device 2C:xx:xx:xx:xx:B6 RSSI: -82
[Bluetooth Mouse]# devices
Device 04:xx:xx:xx:xx:37 iMac de Bernard
Device 48:xx:xx:xx:xx:86 xxxxxxxxxxx
Device 53:xx:xx:xx:xx:26 xxxxxxxxxxx
Device 2C:xx:xx:xx:xx:B6 xxxxxxxxxxx
Device 04:xx:xx:xx:xx:87 xxxxxxxxxxx
Device 6C:xx:xx:xx:xx:88 xxxxxxxxxxx
Device 00:xx:xx:xx:xx:32 Bluetooth Mouse
Device 44:xx:xx:xx:xx:8E xxxxxxxxxxx
Device D4:xx:xx:xx:xx:8E xxxxxxxxxxx
Device 77:xx:xx:xx:xx:77 xxxxxxxxxxx
[CHG] Device 2C:xx:xx:xx:xx:B6 RSSI: -82
[CHG] Device …Run Code Online (Sandbox Code Playgroud) 我在C中使用一个与系统相关的计时器(我无法更改其代码).我可以使用此功能访问它,其中包括:
void start_timer(int duration, void (*callback)(void*), void* arg);
Run Code Online (Sandbox Code Playgroud)
所以我可以给定时器一个回调函数及其void*参数.
我想用作回调的函数是:
void send_message(ipaddr* source, ipaddr* destination, char* message);
Run Code Online (Sandbox Code Playgroud)
我不能直接给这个函数start_timer,因为它与void (*)(void*)所需的类型不匹配.由于C中不存在匿名函数,我无法使用此解决方案(但这是我想要做的):
start_timer(1000, void(*)(void* stuff){
send_message(source, destination, message);
}, NULL);
Run Code Online (Sandbox Code Playgroud)
所以我必须给这个函数命名:
void call_send_message(void* stuff) {
send_message(source, destination, message);
}
start_timer(1000, &call_send_message, NULL);
Run Code Online (Sandbox Code Playgroud)
是否有更美妙的方式来调用send_message函数start_timer?
我有一个以以下结尾的 bash 变量\\r\\n:
$ # Not the real command to get VAR's value, just an example\n$ VAR="$(echo -en 'hello\\r\\n')"\n$ hexdump -C <<< "$VAR"\n00000000 68 65 6c 6c 6f 0d 0a |hello..|\n00000007\nRun Code Online (Sandbox Code Playgroud)\n我想删除\\r(\\nbash 本身已正确处理)。
我可能会修剪它 ( VAR="$(tr -d '\\r' <<< "$VAR")"),但这意味着仅针对该任务运行一个进程。
我尝试使用“删除匹配后缀模式”bash 功能,但找不到要使用的模式(例如, 、${VAR%\\r}、${VAR%\\x0d}\ ${VAR%[\\r]}xe2\x80\x94 但它们都不起作用)。
知道如何在\\r不创建子流程的情况下删除它吗?
我正在写一个带有vim和latex的文档.我最近注意到我使用的一个词("树"),但在我的文档上下文中它是不正确的.我在整个文件中纠正了它.但是,我有习惯在写作时使用这个词而不是正确的词.
是否有可能将此单词声明为临时错误单词(直到缓冲区关闭,这就足够了),使拼写检查器突出显示它?
我试图将其标记为明确的错误词.这不是一个解决方案,因为"树"实际上是一个正确的单词,不应该在其他文档中突出显示.我也尝试搜索它:我的vim配置为在我写它时自动突出显示它.这是一个半解决方案,因为它需要我的最后一次搜索是"树",并且如果我有非常错误的习惯,则难以处理很多单词.
我试图创建一个包含两个浮点数的元组.(4.0, 4.0), 例如.但是,由于两个花车是相同的,我写道4.0, * 2.
我想写的是:(4.0,) * 2.在Python中,将元组乘以一个整数表示为Python,以将元组与其自身连接起来.所以(4.0,) * 2 = (4.0,) + (4.0,) = (4.0, 4.0).好.
我不想做的是4.0 * 2(没有逗号).实际上,这将使浮子4.0本身乘以2:4.0 * 2 = 8.0.好.
但这些比赛都没有发生.而不是8.0或(4.0, 4.0),我有一个
TypeError: 'int' object is not iterable
Run Code Online (Sandbox Code Playgroud)
这个答案令我非常惊讶.这种语法如何导致迭代2(这是该表达式的唯一整数)?