相关疑难解决方法(0)

为什么bool是int的子类?

当通过python-memcached在memcached中存储bool时,我注意到它以整数形式返回.检查库的代码向我显示有一个地方isinstance(val, int)被检查以将值标记为整数.

所以我在python shell中测试了它并注意到以下内容:

>>> isinstance(True, int)
True
>>> issubclass(bool, int)
True
Run Code Online (Sandbox Code Playgroud)

但为什么究竟是bool一个子类int呢?

它有点意义,因为布尔值基本上是一个int,它可以只取两个值,但它需要比实际整数少得多的操作/空间(没有算术,只有一点存储空间)....

python boolean

79
推荐指数
2
解决办法
1万
查看次数

确定字符串中数字的计数和百分比(熊猫)

我在数据集 df 中有一个列,其中包含这样的字符串

Webs
https://www.mhouse.com/107462464135489/posts/please-lets-be-guidedun-is-where-the-code/142970213918047/
https://www.msed.com/IKONINIBWANASEEDMARCH2020.html
https://www.msed.com/
https://carrice.com/jen/stat/1241025420562178050?lang=en
Run Code Online (Sandbox Code Playgroud)

...

我想确定其中的数量和百分比;所以,例如

Count      Percentage
15         (and the percentage compared to the length of the string)
4          ...
0          ...
19         ...
Run Code Online (Sandbox Code Playgroud)

如果我没有错,我会使用 is digit 的组合来确定字符串中的位数,使用 len() 来确定字符串的长度,然后是百分比。

python regex pandas

-1
推荐指数
1
解决办法
152
查看次数

标签 统计

python ×2

boolean ×1

pandas ×1

regex ×1