读 Data type 那一节的时候,我一边做标记,一边嘀咕,虽然这个看起来就很重要,但我以后肯定会搞错。
预见到自己可能会犯什么错,结果这份预见一点作用都没有,该犯的时候还是犯错了。
这不算什么特别光荣的经历。
计算置信区间的时候,需要取平方根 sqrt
。
这行代码不停报错。
提示信息是
cannot convert the series to <class ‘float'>
排查之后,我觉得问题应该是出在了 Math 处理的数据类型上。
因为我使用的是 from math import sqrt
。
虽然没有找到完全一致的 case,但 Stackoverflow 上有人提到:
Math.log is expecting a single number, not array.
– source: https://stackoverflow.com/a/42988384
from numpy import sqrt
之后 re-run 了语句,就没有再报错。
两个 lib 关于 sqrt 的说明:
Numpy
numpy.sqrt(x)
. Return the positive square-root of an array, element-wise.Math
math.sqrt(x)
Return the square root of x.
(Math的说明简洁得令人抓狂。)