Pandas学习笔记,axis的用法
axis=1表示列(1是竖着的),axis=0表示行
在mean()方法中有所不同,mean(axis=0)返回的是各列的平均值
d = ts.get_hist_data('600848', start='2015-01-05', end='2015-01-09') data = pd.DataFrame(d) print(data) print(data.mean(axis=0))
运行结果是
open high close low volume price_change p_change \ date 2015-01-09 11.68 11.71 11.23 11.19 44851.56 -0.44 -3.77 2015-01-08 11.70 11.92 11.67 11.64 56845.71 -0.25 -2.10 2015-01-07 11.58 11.99 11.92 11.48 86681.38 0.31 2.67 2015-01-06 11.13 11.66 11.61 11.03 59199.93 0.35 3.11 2015-01-05 11.16 11.39 11.26 10.89 46383.57 0.14 1.26 ma5 ma10 ma20 v_ma5 v_ma10 v_ma20 turnover date 2015-01-09 11.538 11.363 11.682 58792.43 60665.93 107924.27 1.54 2015-01-08 11.516 11.349 11.647 57268.99 61376.00 105823.50 1.95 2015-01-07 11.366 11.251 11.543 55049.74 61628.07 103010.58 2.97 2015-01-06 11.182 11.155 11.382 54854.38 63401.05 98686.98 2.03 2015-01-05 11.156 11.212 11.370 58648.75 68429.87 100765.24 1.59 open 11.4500 high 11.7340 close 11.5380 low 11.2460 volume 58792.4300 price_change 0.0220 p_change 0.2340 ma5 11.3516 ma10 11.2660 ma20 11.5248 v_ma5 56922.8580 v_ma10 63100.1840 v_ma20 103242.1140 turnover 2.0160 dtype: float64
可以理解为对各列的所有行做平均。