我有一个DataFrame,其列中包含许多缺失值,我希望将其分组:
import pandas as pd
import numpy as np
df = pd.DataFrame({'a': ['1', '2', '3'], 'b': ['4', np.NaN, '6']})
In [4]: df.groupby('b').groups
Out[4]: {'4': [0], '6': [2]}
Run Code Online (Sandbox Code Playgroud)
看到Pandas已经删除了具有NaN目标值的行.(我想要包含这些行!)
由于我需要很多这样的操作(许多cols都缺少值),并且使用比中位数(通常是随机森林)更复杂的函数,我想避免编写太复杂的代码片段.
有什么建议?我应该为此编写一个函数还是有一个简单的解决方案?
我有一个类(dicts 列表),我希望它自己排序:
class Table(list):
…
def sort (self, in_col_name):
self = Table(sorted(self, key=lambda x: x[in_col_name]))
Run Code Online (Sandbox Code Playgroud)
但它根本不起作用.为什么?怎么避免呢?除了在外部进行排序外,例如:
new_table = Table(sorted(old_table, key=lambda x: x['col_name'])
Run Code Online (Sandbox Code Playgroud)
是不是可以操纵对象本身?拥有以下内容更有意义:
class Table(list):
pass
Run Code Online (Sandbox Code Playgroud)
比:
class Table(object):
l = []
…
def sort (self, in_col_name):
self.l = sorted(self.l, key=lambda x: x[in_col_name])
Run Code Online (Sandbox Code Playgroud)
我认为,这是有效的.一般来说,Python中没有任何方法可以改变对象(不仅仅是实例变量)?
我将在chroot环境中将低流量的Web服务器设置到旧的Android手机上。Debian已安装到手机上,并且可以正常工作数月(因此,这是一种特殊的Linux环境)。
Apache2和Python已启动并正在运行。
但是当我启动mysqld时:
root@Motoluxe:~# /usr/sbin/mysqld
... [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
... [Note] /usr/sbin/mysqld (mysqld 5.5.49-0+deb7u1) starting as process 31419 ...
... [Warning] Using unique option prefix myisam-recover instead of myisam-recover-options is deprecated and will be removed in a future release. Please use the full name instead.
... [Note] Plugin 'FEDERATED' is disabled.
... InnoDB: The InnoDB memory heap is …Run Code Online (Sandbox Code Playgroud) 很多时候,我编写 C++ 函数时,似乎const比其他人使用了更多的修饰符。
例如,我编写 Excel .xlsx 文件,并为此使用 LibXL 库,并且文档提到了这样的函数:
bool writeNum(int row, int col, double value, Format* format = 0)
Run Code Online (Sandbox Code Playgroud)
我碰巧继承了这个函数,我的签名如下:
bool XLAPIENTRY writeNum(const int row, const int col, const double value, IFormatT<wchar_t> * format = 0);
Run Code Online (Sandbox Code Playgroud)
请注意const int行和列的 s。
const问题:省略s安全吗int?(很明显,对于指针来说,忽略指针的 const 是危险的,但是做一些 an 的本地副本int并不是那么危险)。请注意,包含 writeNum 函数的原始标头int也没有提到 const-ing s。为什么这里const省略了修饰符?