利用Python进行数据分析
最新书摘:
-
猪七七2018-05-22......array slices are views on the original array. This means that the data is not copied, and any modifications to the view will be reflected in the source array.
-
九识澪2018-04-20dateutil可以解析几乎所有人类能够理解的日期表示形式。(很遗憾,中文不行)
-
九识澪2017-08-20从0开始,步长1和-1出现的概率相等。通过内置的random模块以纯python的方式实现1000步的随机漫步:In [1]: import randomIn [2]: position=0In [3]: walk=[position]In [4]: steps=1000In [5]: for i in xrange(steps):...: step=1 if random.randint(0,1) else -1...: position += step...: walk.append(position)...:我用np.random模块一次性随机产生1000个“掷硬币的结果,将其分别设置为1或-1,然后计算累计和:In [6]: nsteps=1000In [9]: draws=np.random.randint(0,2,size=nsteps)In [11]: steps=np.where(draws>0,1,-1)In [12]: walk=steps.cumsum()In [13]: walk.min()Out[13]: -15In [14]: walk.max()Out[14]: 21接下来我们想计算:随机漫步过程中的第一次到达某个特定的值的时间。假设我们知道需要多久才能距离0点至少10步远。np.ads(walk)>=10可以得到一个布尔型数组,表示的距离是否达到或者超过10。可以使用argmax来解决这个问题:In [15]: (np.abs(walk)>=10).argmax()Out[15]: 1394.6.1 一次模拟多个随机漫步希望模拟多个随机漫步过程,只需要对上面的代码做一点点修改即可。只要给numpy.random的函数传入一个二元元组就可以产生一个二维数组。然后...
-
lleiou2017-07-12return totals.order(ascending=False)[:n]
-
牛肉干2017-02-27The probability density function for lognorm is:lognorm.pdf(x, s) = 1 / (s*x*sqrt(2*pi)) * exp(-1/2*(log(x)/s)**2)for x > 0, s > 0.lognorm takes s as a shape parameter.The probability density above is defined in the “standardized” form. To shift and/or scale the distribution use the loc and scale parameters. Specifically, lognorm.pdf(x, s, loc, scale) is identically equivalent to lognorm.pdf(y, s) / scale with y = (x - loc) / scale.A common parametrization for a lognormal random variable Y is in terms of the mean, mu, and standard deviation, sigma, of the unique normally distributed random variable X such that exp(X) = Y. This parametrization corresponds to setting s = sigma and scale = exp(mu).
-
牛肉干2017-02-12records = [json.loads(line) for line in open(path)]
-
牛肉干2017-02-12数组切片是原始数据的视图。这意味着数据不会被复制,视图上的任何修改都会直接反映到源数组上。