#/usr/bin/python def Z_Score(data): lenth = len(data) total = sum(data) ave = float(total)/lenth tempsum = sum([pow(data[i] - ave,2) for i in range(lenth)]) tempsum = pow(float(tempsum)/lenth,0.5) for i in range(lenth): data[i] = (data[i] - ave)/temp
在代码过程中中,将代码过程中比较好的代码段珍藏起来,如下的代码是关于python集合使用范例的代码,希望能对大伙有用. # sets are unordered collections of unique hashable elements # Python23 tested vegaseat 09mar2005 # Python v2.4 has sets built in import sets print "List the functions within module 'sets':&
前言 编写python程序有时候需要对代码块进行comment,本文对此介绍. 方法 python注释的三种方法: 1.井号注释单行代码: # 2.三个单引号或三个双引号注释语句块: ''' 或者" " " 3.井号加两个百分号画出语句块分界线: #%% 代码 ''' #data.csv is created by make_data.py data=pd.read_csv('data.csv') ''' #get X and y X=data.iloc[:,:-1].val
Python方法oslo_service.loopingcall.LoopingCallDone代码示例 demo: from oslo_service import loopingcall def _wait_for_image_state(): global num num = def _wait_for_state(): global num print num num = num + if num == : raise loopingcall.LoopingCallDone() time
1.如何反向迭代一个序列 #如果是一个list,最快的方法使用reversetempList = [1,2,3,4]tempList.reverse()for x in tempList: print x #如果不是list,需要手动重排templist = (1,2,3,4)for i in range(len(templist)-1,-1,-1): print templist[i] 2.如何查询和替换一个文本中的字符串 #最简单的方法使用replace()tempstr = "