1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
def pearsonr_2D(x, y): """computes pearson correlation coefficient where x is a 1D and y a 2D array""" upper = np.sum((x - np.mean(x,axis=0)) * (y - np.mean(y, axis=0)), axis=0) lower = np.sqrt(np.sum(np.power(x - np.mean(x,axis=0), 2),axis=0) * np.sum(np.power(y - np.mean(y, axis=0), 2), axis=0)) rho = upper / lower return rho A = np.array([[[1,3,4],[4,6,5]],[[5,7,8],[1,2,23]],[[3,9,4],[5,7,5]]]) B = np.array([[[7,1,3],[14,4,2]],[[15,6,1],[6,7,91]],[[3,9,4],[5,7,5]]]) c = pearsonr_2D(A,B)
for i,region in enumerate(region): print(i,region)
df = pd.DataFrame(columns = ["ebayno", "p_sku", "sale", "sku"]) df = df.append(dframe1.loc[dframe1.p_sku == ps], ignore_index=True)
df = df.append([{'site':site,'MB':mb,'NMB':nmb,'NME':nme,'r2':r2}],ignore_index=True) 来自 <http://blog.csdn.net/zn505119020/article/details/77324029>
合并 df = pd.concat([inputdf,classdf],axis=1)
根据分组统计,对不同行操作 gp_col = 'SITE' df_max = obs.groupby(gp_col)[species].max() df_min = obs.groupby(gp_col)[species2].min()
插入列 insert(位置,列名,数据) df_max.insert(0,"站点",sitename)
DataFrame 切片操作,loc, iloc print df.loc[1:3, ['total_bill', 'tip']] print df.loc[1:3, 'tip': 'total_bill'] print df.iloc[1:3, [1, 2]] print df.iloc[1:3, 1: 3]
来自 <https://blog.csdn.net/ly_ysys629/article/details/55224284>
获取数据框列名 print(df.columns) 获取数据框列 df["column-name"] 选取行 df[df["column-name"]=="spec-name"] 选取数据 df.column[index] df.ix[0,1]
列表转换成dataframe df = pd.DataFrame([w1_p,w2_p,w3_p,w4_p],index=['w1_pre','w2_pre','w3_pre','w4_pre']) 修改dataframe的列名 df.columns=['site','time','aqi','so2','no2','pm10','co','o3','pm2_5']
|