1. list删除元素
# get rid of the suspend shares
for k in range(0, num_tmp):
code_tmp = suspend_code[k]
if code_tmp in sec_code: #判断该值是否在list中
idx = sec_code.index(code_tmp) #查找list中某元素的值等于code_tmp的所有元素的索引
del sec_code[idx] #删除索引idx的list元素
2. python中的字符串datetime之间的转化(扩展知识还有时间戳)
ipo_date_str = ipo_date[k].strftime('%Y-%m-%d') #detetime转成字符串
3. math常用数学运算,对数字操作
s_factor[i] = math.fabs(pct_chg[i])/math.sqrt(volume[i]) #绝对值fabs,算术平方根sqrt
4. numpy数组排序
idx_sorted = np.argsort(-s_factor) #从大到小排序后的返回数组索引
5. list表元素之间的操作
volume_sum = sum(volume) #list所有元素求和
map(lambda x, y: x + y, list1, list2) #两个list对应元素求和
6. numpy求数组均值
mean_factor = np.mean(factors)
7. list添加元素,创建空表并添加元素构建list
time_date = []
time_date.append(current_day)
8. numpy求相关系数
data = np.array([smart_money_factor, time_yiled])
facor_ic[k] = np.corrcoef(data)