首页 > 代码库 > Python基本数据统计(二)

Python基本数据统计(二)

1. 便捷数据获取

  1.2 网络数据获取:

    1.2.1 urllib, urllib2, httplib, httplib2和正则表达式(python3中为urllib.request, http.client)

技术分享获取AXP近一年的股票数据

2. 数据准备和整理

3. 数据显示

4. 数据选择

  4.1 选择行

    4.1.1 索引

技术分享obj.ix[val

    4.1.2 切片

技术分享obj[‘xx‘:‘xxx‘]

  4.2 选择列

技术分享obj[‘xx‘]
技术分享obj.xx

  4.3 行、列  - 标签label ( loc )

技术分享
In [64]: djidf.loc[1:5,]
Out[64]: 
   code                      name lasttrade
1   AXP  American Express Company    76.200
2    BA        The Boeing Company   159.530
3   CAT          Caterpillar Inc.    94.580
4  CSCO                    思科系?公司    30.100
5   CVX       Chevron Corporation   115.600

In [65]: djidf.loc[:,[code,lasttrade]]
Out[65]: 
    code lasttrade
0   AAPL   120.000
1    AXP    76.200
2     BA   159.530
3    CAT    94.580
...
29   XOM    85.890
obj.loc[x : xx, [‘y‘,‘yy‘] ]

  4.4 行和列的区域  - 标签label ( loc 和 at )

技术分享
In [66]: djidf.loc[1:5,[code,lasttrade]]
Out[66]: 
   code lasttrade
1   AXP    76.200
2    BA   159.530
3   CAT    94.580
4  CSCO    30.100
5   CVX   115.600

In [67]: djidf.loc[1,lasttrade]
Out[67]: 76.200

In [68]: djidf.at[1,lasttrade]
Out[68]: 76.200
obj.loc[x, ‘y‘]

  4.5 行、列和区域 ( iloc 和 iat )

技术分享
In [69]: djidf.loc[1:5,[code,lasttrade]]
Out[69]: 
   code lasttrade
1   AXP    76.200
2    BA   159.530
3   CAT    94.580
4  CSCO    30.100
5   CVX   115.600

In [70]: djidf.iloc[1:6,[0,2]]
Out[70]: 
   code lasttrade
1   AXP    76.200
2    BA   159.530
3   CAT    94.580
4  CSCO    30.100
5   CVX   115.600

In [71]: djidf.loc[1,lasttrade]
Out[71]: 76.200

In [72]: djidf.at[1,lasttrade]
Out[72]: 76.200

In [73]: djidf.iloc[1,2]
Out[73]: 76.200

In [74]: djidf.iat[1,2]
Out[74]: 76.200
obj.iloc[ a:b, [c,d] ]

  4.5 条件筛选

技术分享
In [77]: quotesdf[quotesdf.index >= 2016-12-20]
Out[77]: 
                 open      close       high        low     volume
2016-12-20  74.681487  74.741230  75.179363  74.213482  3244900.0
...
2017-01-20  75.989998  76.199997  76.910004  75.389999  8382000.0

In [78]: quotesdf[(quotesdf.index >= 2016-12-20) & (quotesdf.close >=76)]
Out[78]: 
                 open      close       high        low     volume
2017-01-04  75.260002  76.260002  76.550003  75.059998  4635800.0
...
2017-01-20  75.989998  76.199997  76.910004  75.389999  8382000.0
quotesdf[(quotesdf.index >= ‘2016-12-20‘) & (quotesdf.close >=76)]

5. 简单统计与处理

6. Grouping

7. Merge

Python基本数据统计(二)