pandas 入門


```python
import pandas as pd
```


```python
# 他の使いそうなライブラリもインポート
import math
import numpy as np
import matplotlib.pyplot as plt

# jupyter notebook 用の inline 表示リクエスト
%matplotlib inline
```

## pandas のデータ形式

pandas DataFrame という 2 次元配列のデータ形式を主として扱う.

csv を読み込んで DataFrame にしていい感じに計算させることが多い.

## pandas.DataFrame

```python
pandas.DataFrame(data=None, index=None, columns=None, dtype=None, copy=False)
```

自分で初期化する場合, 上のように作る.

data には numpy.ndarray, dict, DataFrame が入る.


```python
# ndarray の場合
pd.DataFrame([[1, 2, 3], [4, 5, 6]])
```




<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>0</th>
      <th>1</th>
      <th>2</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>1</td>
      <td>2</td>
      <td>3</td>
    </tr>
    <tr>
      <th>1</th>
      <td>4</td>
      <td>5</td>
      <td>6</td>
    </tr>
  </tbody>
</table>
</div>




```python
# dict の場合
pd.DataFrame({'a': [1, 4], 'b': [2, 5], 'c': [3, 6]})
```




<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>a</th>
      <th>b</th>
      <th>c</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>1</td>
      <td>2</td>
      <td>3</td>
    </tr>
    <tr>
      <th>1</th>
      <td>4</td>
      <td>5</td>
      <td>6</td>
    </tr>
  </tbody>
</table>
</div>




```python
# ndarray で dict と同値な df を出す
df1 = pd.DataFrame([[1, 2, 3], [4, 5, 6]], columns=['a', 'b', 'c'])
df2 = pd.DataFrame({'a': [1, 4], 'b': [2, 5], 'c': [3, 6]})
df1.equals(df2)
```




    True




```python
# データ型の確認
df1.dtypes
```




    a    int64
    b    int64
    c    int64
    dtype: object




```python
# numpy.ndarray に変換
df1.values
```




    array([[1, 2, 3],
           [4, 5, 6]])




```python
# 要素数
df1.size
```




    6



### DataFrame へのアクセス


```python
df1.a
```




    0    1
    1    4
    Name: a, dtype: int64




```python
df1['a']
```




    0    1
    1    4
    Name: a, dtype: int64




```python
df1.loc[0]
```




    a    1
    b    2
    c    3
    Name: 0, dtype: int64




```python
df1.loc
```




    <pandas.core.indexing._LocIndexer at 0x114ea6550>



## csv を読み込んで DataFrame にする

```python
pandas.read_csv(filepath_or_buffer, sep=', ', delimiter=None, header='infer', names=None, index_col=None, usecols=None, squeeze=False, prefix=None, mangle_dupe_cols=True, dtype=None, engine=None, converters=None, true_values=None, false_values=None, skipinitialspace=False, skiprows=None, nrows=None, na_values=None, keep_default_na=True, na_filter=True, verbose=False, skip_blank_lines=True, parse_dates=False, infer_datetime_format=False, keep_date_col=False, date_parser=None, dayfirst=False, iterator=False, chunksize=None, compression='infer', thousands=None, decimal=b'.', lineterminator=None, quotechar='"', quoting=0, escapechar=None, comment=None, encoding=None, dialect=None, tupleize_cols=None, error_bad_lines=True, warn_bad_lines=True, skipfooter=0, skip_footer=0, doublequote=True, delim_whitespace=False, as_recarray=None, compact_ints=None, use_unsigned=None, low_memory=True, buffer_lines=None, memory_map=False, float_precision=None)
```

`sample_01_btc.csv`

BTC-USD 取引の 1 分毎のデータ.

```
Timestamp,Open,High,Low,Close,Volume_(BTC),Volume_(Currency),Weighted_Price
1508454000,5714.5,5722,5707.08,5722,4.1163103,23517.533993,5713.2558721
1508454060,5709.99,5722,5709.56,5711.16,4.32023995,24680.498868,5712.7611322
1508454120,5711.16,5718.8,5710.01,5710.01,3.85405094,22020.718724,5713.6553374
1508454180,5711.36,5711.36,5706.66,5706.66,1.16405304,6646.2711683,5709.5947864
1508454240,5706.48,5710.87,5706.31,5706.31,1.38535201,7908.5236431,5708.674464
1508454300,5718.57,5722.81,5706,5706,0.81982085,4685.1229798,5714.8131568
1508454360,5721.32,5721.32,5721.32,5721.32,0.1621444,927.67999861,5721.32
1508454420,5707.22,5725.4,5707.22,5709.89,0.30563931,1748.2169415,5719.8694158
1508454480,5719.22,5719.22,5709.89,5709.89,1.98576163,11338.667829,5709.9843496
1508454540,5725.23,5725.23,5709.91,5709.91,0.01087959,62.218800956,5718.8553021
1508454600,5720.41,5720.42,5709.91,5720.41,1.38101969,7889.5914892,5712.8740063
1508454660,5709.89,5720.41,5709.89,5720.41,1.06840668,6111.4859753,5720.1869753
1508454720,5715.85,5723.19,5715.85,5723.19,0.30664325,1754.2302403,5720.7528303
1508454780,5724.43,5724.43,5724.42,5724.42,10.200957,58394.56428,5724.420197
1508454840,5728,5728,5720.7,5727.2,0.52788184,3020.9305932,5722.7401367
1508454900,5728,5729,5724.63,5724.63,1.02945547,5895.6735162,5726.9825534
1508454960,5724.63,5729,5724.63,5729,0.21323798,1220.7260847,5724.7122893
1508455020,5727.71,5728.99,5727.71,5728.99,0.20431343,1170.3316773,5728.1191811
1508455080,5728.99,5729,5728.99,5729,0.32211059,1845.3691499,5728.9924864
1508455140,5720.01,5720.01,5720.01,5720.01,0.045575,260.68945575,5720.01
1508455200,5720,5726.06,5720,5726.06,0.1121888,642.24708813,5724.6987946
1508455260,5720.01,5725.82,5720,5725.82,0.24468336,1400.8095215,5724.9889062
1508455320,5725.82,5725.82,5725.82,5725.82,0.010029,57.42424878,5725.82
1508455380,5724.24,5724.49,5721.38,5724.49,0.52595295,3010.6402539,5724.1626915
1508455440,5724.49,5724.49,5723.88,5723.88,0.23215461,1328.9239824,5724.3058081
1508455500,5721.39,5721.39,5721.38,5721.38,0.26093204,1492.8938093,5721.389406
1508455560,5724.44,5724.44,5720,5720,0.03822585,218.78021503,5723.3577548
1508455620,5719.99,5719.99,5706,5706,5.69254452,32498.767151,5709.0053555
1508455680,5719.95,5719.95,5719.95,5719.95,0.049629,283.87539855,5719.95
1508455740,5719.95,5719.95,5719.95,5719.95,0.049629,283.87539855,5719.95
1508455800,5706.01,5708.84,5706.01,5708.84,0.0482098,275.20505463,5708.4877895
1508455860,5706.01,5706.01,5706.01,5706.01,0.00790223,45.090203402,5706.01
1508455920,5708.85,5708.85,5706,5708.84,0.50472844,2880.0455522,5706.1289279
1508455980,5708.85,5708.85,5706,5708.84,0.50472844,2880.0455522,5706.1289279
1508456040,5706,5706,5704.01,5704.01,0.40618257,2317.5307731,5705.6381645
1508456100,5704.01,5710.27,5704.01,5710.27,0.78124874,4457.2656092,5705.3091813
1508456160,5710.27,5710.57,5710.27,5710.57,0.8436208,4817.5531388,5710.5670448
1508456220,5710.57,5710.57,5704.01,5707.21,0.37128213,2119.9167574,5709.7193376
1508456280,5704,5704.01,5704,5704,0.77077686,4396.5129217,5704.0022214
1508456340,5704.01,5704.01,5704,5704,0.0598,341.0994,5704.0033445
1508456400,5704.01,5704.01,5702.43,5702.43,44.40229928,253201.25248,5702.4356077
1508456460,5702.43,5702.43,5702.43,5702.43,0.01491091,85.028420511,5702.43
1508456520,5702.43,5704.01,5702.43,5704,0.80557148,4594.9691244,5703.9868447
1508456580,5702.44,5702.44,5702.44,5702.44,0.01970529,112.36823391,5702.44
1508456640,5704.01,5704.01,5704.01,5704.01,0.07418565,423.15568946,5704.01
1508456700,5704.01,5704.01,5702.43,5702.43,0.21684081,1236.8403005,5703.9092435
1508456760,5704.01,5704.01,5702.43,5702.43,1.80248464,10278.606035,5702.4652563
1508456820,5702.43,5704.01,5702.43,5702.43,1.0176104,5802.9480004,5702.524267
1508456880,5703,5703,5702.99,5702.99,0.06074779,346.44419697,5702.9926022
1508456940,5703,5703,5702.43,5702.43,0.2174653,1240.1733699,5702.8563632
1508457000,5702.43,5702.43,5702.43,5702.43,5.80725974,33115.492159,5702.43
1508457060,5703.92,5704.01,5702.43,5704,4.90530398,27979.233447,5703.8735134
1508457120,5703.9,5703.95,5703.9,5703.95,0.05126788,292.4291083,5703.9438397
1508457180,5703.9,5703.95,5703.9,5703.95,0.05126788,292.4291083,5703.9438397
1508457240,5702.43,5702.43,5698.5,5698.5,2.64309578,15069.597851,5701.4951802
1508457300,5697,5697,5696.16,5696.17,0.08723364,496.91077327,5696.3205166
1508457360,5690.88,5690.88,5690.88,5690.88,0.16894078,961.42170609,5690.88
1508457420,5698.13,5704.1,5695.63,5704.1,2.31166152,13174.852877,5699.3001628
1508457480,5695.62,5695.64,5694,5695.64,0.12964714,738.4096468,5695.5336369
1508457540,5700.39,5700.39,5698.69,5698.69,0.08542622,486.92979839,5700.0040314
1508457600,5700,5700,5698.68,5700,0.11684654,665.91386047,5699.0464627
```


```python
import datetime
# timestamp を datetime に変換
timestamp_parser = lambda date: datetime.datetime.fromtimestamp(date)
df = pd.read_csv("./sample_01_btc.csv", index_col=0, parse_dates=0, date_parser=timestamp_parser)
df
```




<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Open</th>
      <th>High</th>
      <th>Low</th>
      <th>Close</th>
      <th>Volume_(BTC)</th>
      <th>Volume_(Currency)</th>
      <th>Weighted_Price</th>
    </tr>
    <tr>
      <th>Timestamp</th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>2017-10-20 08:00:00</th>
      <td>5714.50</td>
      <td>5722.00</td>
      <td>5707.08</td>
      <td>5722.00</td>
      <td>4.116310</td>
      <td>23517.533993</td>
      <td>5713.255872</td>
    </tr>
    <tr>
      <th>2017-10-20 08:01:00</th>
      <td>5709.99</td>
      <td>5722.00</td>
      <td>5709.56</td>
      <td>5711.16</td>
      <td>4.320240</td>
      <td>24680.498868</td>
      <td>5712.761132</td>
    </tr>
    <tr>
      <th>2017-10-20 08:02:00</th>
      <td>5711.16</td>
      <td>5718.80</td>
      <td>5710.01</td>
      <td>5710.01</td>
      <td>3.854051</td>
      <td>22020.718724</td>
      <td>5713.655337</td>
    </tr>
    <tr>
      <th>2017-10-20 08:03:00</th>
      <td>5711.36</td>
      <td>5711.36</td>
      <td>5706.66</td>
      <td>5706.66</td>
      <td>1.164053</td>
      <td>6646.271168</td>
      <td>5709.594786</td>
    </tr>
    <tr>
      <th>2017-10-20 08:04:00</th>
      <td>5706.48</td>
      <td>5710.87</td>
      <td>5706.31</td>
      <td>5706.31</td>
      <td>1.385352</td>
      <td>7908.523643</td>
      <td>5708.674464</td>
    </tr>
    <tr>
      <th>2017-10-20 08:05:00</th>
      <td>5718.57</td>
      <td>5722.81</td>
      <td>5706.00</td>
      <td>5706.00</td>
      <td>0.819821</td>
      <td>4685.122980</td>
      <td>5714.813157</td>
    </tr>
    <tr>
      <th>2017-10-20 08:06:00</th>
      <td>5721.32</td>
      <td>5721.32</td>
      <td>5721.32</td>
      <td>5721.32</td>
      <td>0.162144</td>
      <td>927.679999</td>
      <td>5721.320000</td>
    </tr>
    <tr>
      <th>2017-10-20 08:07:00</th>
      <td>5707.22</td>
      <td>5725.40</td>
      <td>5707.22</td>
      <td>5709.89</td>
      <td>0.305639</td>
      <td>1748.216941</td>
      <td>5719.869416</td>
    </tr>
    <tr>
      <th>2017-10-20 08:08:00</th>
      <td>5719.22</td>
      <td>5719.22</td>
      <td>5709.89</td>
      <td>5709.89</td>
      <td>1.985762</td>
      <td>11338.667829</td>
      <td>5709.984350</td>
    </tr>
    <tr>
      <th>2017-10-20 08:09:00</th>
      <td>5725.23</td>
      <td>5725.23</td>
      <td>5709.91</td>
      <td>5709.91</td>
      <td>0.010880</td>
      <td>62.218801</td>
      <td>5718.855302</td>
    </tr>
    <tr>
      <th>2017-10-20 08:10:00</th>
      <td>5720.41</td>
      <td>5720.42</td>
      <td>5709.91</td>
      <td>5720.41</td>
      <td>1.381020</td>
      <td>7889.591489</td>
      <td>5712.874006</td>
    </tr>
    <tr>
      <th>2017-10-20 08:11:00</th>
      <td>5709.89</td>
      <td>5720.41</td>
      <td>5709.89</td>
      <td>5720.41</td>
      <td>1.068407</td>
      <td>6111.485975</td>
      <td>5720.186975</td>
    </tr>
    <tr>
      <th>2017-10-20 08:12:00</th>
      <td>5715.85</td>
      <td>5723.19</td>
      <td>5715.85</td>
      <td>5723.19</td>
      <td>0.306643</td>
      <td>1754.230240</td>
      <td>5720.752830</td>
    </tr>
    <tr>
      <th>2017-10-20 08:13:00</th>
      <td>5724.43</td>
      <td>5724.43</td>
      <td>5724.42</td>
      <td>5724.42</td>
      <td>10.200957</td>
      <td>58394.564280</td>
      <td>5724.420197</td>
    </tr>
    <tr>
      <th>2017-10-20 08:14:00</th>
      <td>5728.00</td>
      <td>5728.00</td>
      <td>5720.70</td>
      <td>5727.20</td>
      <td>0.527882</td>
      <td>3020.930593</td>
      <td>5722.740137</td>
    </tr>
    <tr>
      <th>2017-10-20 08:15:00</th>
      <td>5728.00</td>
      <td>5729.00</td>
      <td>5724.63</td>
      <td>5724.63</td>
      <td>1.029455</td>
      <td>5895.673516</td>
      <td>5726.982553</td>
    </tr>
    <tr>
      <th>2017-10-20 08:16:00</th>
      <td>5724.63</td>
      <td>5729.00</td>
      <td>5724.63</td>
      <td>5729.00</td>
      <td>0.213238</td>
      <td>1220.726085</td>
      <td>5724.712289</td>
    </tr>
    <tr>
      <th>2017-10-20 08:17:00</th>
      <td>5727.71</td>
      <td>5728.99</td>
      <td>5727.71</td>
      <td>5728.99</td>
      <td>0.204313</td>
      <td>1170.331677</td>
      <td>5728.119181</td>
    </tr>
    <tr>
      <th>2017-10-20 08:18:00</th>
      <td>5728.99</td>
      <td>5729.00</td>
      <td>5728.99</td>
      <td>5729.00</td>
      <td>0.322111</td>
      <td>1845.369150</td>
      <td>5728.992486</td>
    </tr>
    <tr>
      <th>2017-10-20 08:19:00</th>
      <td>5720.01</td>
      <td>5720.01</td>
      <td>5720.01</td>
      <td>5720.01</td>
      <td>0.045575</td>
      <td>260.689456</td>
      <td>5720.010000</td>
    </tr>
    <tr>
      <th>2017-10-20 08:20:00</th>
      <td>5720.00</td>
      <td>5726.06</td>
      <td>5720.00</td>
      <td>5726.06</td>
      <td>0.112189</td>
      <td>642.247088</td>
      <td>5724.698795</td>
    </tr>
    <tr>
      <th>2017-10-20 08:21:00</th>
      <td>5720.01</td>
      <td>5725.82</td>
      <td>5720.00</td>
      <td>5725.82</td>
      <td>0.244683</td>
      <td>1400.809522</td>
      <td>5724.988906</td>
    </tr>
    <tr>
      <th>2017-10-20 08:22:00</th>
      <td>5725.82</td>
      <td>5725.82</td>
      <td>5725.82</td>
      <td>5725.82</td>
      <td>0.010029</td>
      <td>57.424249</td>
      <td>5725.820000</td>
    </tr>
    <tr>
      <th>2017-10-20 08:23:00</th>
      <td>5724.24</td>
      <td>5724.49</td>
      <td>5721.38</td>
      <td>5724.49</td>
      <td>0.525953</td>
      <td>3010.640254</td>
      <td>5724.162691</td>
    </tr>
    <tr>
      <th>2017-10-20 08:24:00</th>
      <td>5724.49</td>
      <td>5724.49</td>
      <td>5723.88</td>
      <td>5723.88</td>
      <td>0.232155</td>
      <td>1328.923982</td>
      <td>5724.305808</td>
    </tr>
    <tr>
      <th>2017-10-20 08:25:00</th>
      <td>5721.39</td>
      <td>5721.39</td>
      <td>5721.38</td>
      <td>5721.38</td>
      <td>0.260932</td>
      <td>1492.893809</td>
      <td>5721.389406</td>
    </tr>
    <tr>
      <th>2017-10-20 08:26:00</th>
      <td>5724.44</td>
      <td>5724.44</td>
      <td>5720.00</td>
      <td>5720.00</td>
      <td>0.038226</td>
      <td>218.780215</td>
      <td>5723.357755</td>
    </tr>
    <tr>
      <th>2017-10-20 08:27:00</th>
      <td>5719.99</td>
      <td>5719.99</td>
      <td>5706.00</td>
      <td>5706.00</td>
      <td>5.692545</td>
      <td>32498.767151</td>
      <td>5709.005356</td>
    </tr>
    <tr>
      <th>2017-10-20 08:28:00</th>
      <td>5719.95</td>
      <td>5719.95</td>
      <td>5719.95</td>
      <td>5719.95</td>
      <td>0.049629</td>
      <td>283.875399</td>
      <td>5719.950000</td>
    </tr>
    <tr>
      <th>2017-10-20 08:29:00</th>
      <td>5719.95</td>
      <td>5719.95</td>
      <td>5719.95</td>
      <td>5719.95</td>
      <td>0.049629</td>
      <td>283.875399</td>
      <td>5719.950000</td>
    </tr>
    <tr>
      <th>...</th>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
      <td>...</td>
    </tr>
    <tr>
      <th>2017-10-20 08:31:00</th>
      <td>5706.01</td>
      <td>5706.01</td>
      <td>5706.01</td>
      <td>5706.01</td>
      <td>0.007902</td>
      <td>45.090203</td>
      <td>5706.010000</td>
    </tr>
    <tr>
      <th>2017-10-20 08:32:00</th>
      <td>5708.85</td>
      <td>5708.85</td>
      <td>5706.00</td>
      <td>5708.84</td>
      <td>0.504728</td>
      <td>2880.045552</td>
      <td>5706.128928</td>
    </tr>
    <tr>
      <th>2017-10-20 08:33:00</th>
      <td>5708.85</td>
      <td>5708.85</td>
      <td>5706.00</td>
      <td>5708.84</td>
      <td>0.504728</td>
      <td>2880.045552</td>
      <td>5706.128928</td>
    </tr>
    <tr>
      <th>2017-10-20 08:34:00</th>
      <td>5706.00</td>
      <td>5706.00</td>
      <td>5704.01</td>
      <td>5704.01</td>
      <td>0.406183</td>
      <td>2317.530773</td>
      <td>5705.638165</td>
    </tr>
    <tr>
      <th>2017-10-20 08:35:00</th>
      <td>5704.01</td>
      <td>5710.27</td>
      <td>5704.01</td>
      <td>5710.27</td>
      <td>0.781249</td>
      <td>4457.265609</td>
      <td>5705.309181</td>
    </tr>
    <tr>
      <th>2017-10-20 08:36:00</th>
      <td>5710.27</td>
      <td>5710.57</td>
      <td>5710.27</td>
      <td>5710.57</td>
      <td>0.843621</td>
      <td>4817.553139</td>
      <td>5710.567045</td>
    </tr>
    <tr>
      <th>2017-10-20 08:37:00</th>
      <td>5710.57</td>
      <td>5710.57</td>
      <td>5704.01</td>
      <td>5707.21</td>
      <td>0.371282</td>
      <td>2119.916757</td>
      <td>5709.719338</td>
    </tr>
    <tr>
      <th>2017-10-20 08:38:00</th>
      <td>5704.00</td>
      <td>5704.01</td>
      <td>5704.00</td>
      <td>5704.00</td>
      <td>0.770777</td>
      <td>4396.512922</td>
      <td>5704.002221</td>
    </tr>
    <tr>
      <th>2017-10-20 08:39:00</th>
      <td>5704.01</td>
      <td>5704.01</td>
      <td>5704.00</td>
      <td>5704.00</td>
      <td>0.059800</td>
      <td>341.099400</td>
      <td>5704.003344</td>
    </tr>
    <tr>
      <th>2017-10-20 08:40:00</th>
      <td>5704.01</td>
      <td>5704.01</td>
      <td>5702.43</td>
      <td>5702.43</td>
      <td>44.402299</td>
      <td>253201.252480</td>
      <td>5702.435608</td>
    </tr>
    <tr>
      <th>2017-10-20 08:41:00</th>
      <td>5702.43</td>
      <td>5702.43</td>
      <td>5702.43</td>
      <td>5702.43</td>
      <td>0.014911</td>
      <td>85.028421</td>
      <td>5702.430000</td>
    </tr>
    <tr>
      <th>2017-10-20 08:42:00</th>
      <td>5702.43</td>
      <td>5704.01</td>
      <td>5702.43</td>
      <td>5704.00</td>
      <td>0.805571</td>
      <td>4594.969124</td>
      <td>5703.986845</td>
    </tr>
    <tr>
      <th>2017-10-20 08:43:00</th>
      <td>5702.44</td>
      <td>5702.44</td>
      <td>5702.44</td>
      <td>5702.44</td>
      <td>0.019705</td>
      <td>112.368234</td>
      <td>5702.440000</td>
    </tr>
    <tr>
      <th>2017-10-20 08:44:00</th>
      <td>5704.01</td>
      <td>5704.01</td>
      <td>5704.01</td>
      <td>5704.01</td>
      <td>0.074186</td>
      <td>423.155689</td>
      <td>5704.010000</td>
    </tr>
    <tr>
      <th>2017-10-20 08:45:00</th>
      <td>5704.01</td>
      <td>5704.01</td>
      <td>5702.43</td>
      <td>5702.43</td>
      <td>0.216841</td>
      <td>1236.840301</td>
      <td>5703.909244</td>
    </tr>
    <tr>
      <th>2017-10-20 08:46:00</th>
      <td>5704.01</td>
      <td>5704.01</td>
      <td>5702.43</td>
      <td>5702.43</td>
      <td>1.802485</td>
      <td>10278.606035</td>
      <td>5702.465256</td>
    </tr>
    <tr>
      <th>2017-10-20 08:47:00</th>
      <td>5702.43</td>
      <td>5704.01</td>
      <td>5702.43</td>
      <td>5702.43</td>
      <td>1.017610</td>
      <td>5802.948000</td>
      <td>5702.524267</td>
    </tr>
    <tr>
      <th>2017-10-20 08:48:00</th>
      <td>5703.00</td>
      <td>5703.00</td>
      <td>5702.99</td>
      <td>5702.99</td>
      <td>0.060748</td>
      <td>346.444197</td>
      <td>5702.992602</td>
    </tr>
    <tr>
      <th>2017-10-20 08:49:00</th>
      <td>5703.00</td>
      <td>5703.00</td>
      <td>5702.43</td>
      <td>5702.43</td>
      <td>0.217465</td>
      <td>1240.173370</td>
      <td>5702.856363</td>
    </tr>
    <tr>
      <th>2017-10-20 08:50:00</th>
      <td>5702.43</td>
      <td>5702.43</td>
      <td>5702.43</td>
      <td>5702.43</td>
      <td>5.807260</td>
      <td>33115.492159</td>
      <td>5702.430000</td>
    </tr>
    <tr>
      <th>2017-10-20 08:51:00</th>
      <td>5703.92</td>
      <td>5704.01</td>
      <td>5702.43</td>
      <td>5704.00</td>
      <td>4.905304</td>
      <td>27979.233447</td>
      <td>5703.873513</td>
    </tr>
    <tr>
      <th>2017-10-20 08:52:00</th>
      <td>5703.90</td>
      <td>5703.95</td>
      <td>5703.90</td>
      <td>5703.95</td>
      <td>0.051268</td>
      <td>292.429108</td>
      <td>5703.943840</td>
    </tr>
    <tr>
      <th>2017-10-20 08:53:00</th>
      <td>5703.90</td>
      <td>5703.95</td>
      <td>5703.90</td>
      <td>5703.95</td>
      <td>0.051268</td>
      <td>292.429108</td>
      <td>5703.943840</td>
    </tr>
    <tr>
      <th>2017-10-20 08:54:00</th>
      <td>5702.43</td>
      <td>5702.43</td>
      <td>5698.50</td>
      <td>5698.50</td>
      <td>2.643096</td>
      <td>15069.597851</td>
      <td>5701.495180</td>
    </tr>
    <tr>
      <th>2017-10-20 08:55:00</th>
      <td>5697.00</td>
      <td>5697.00</td>
      <td>5696.16</td>
      <td>5696.17</td>
      <td>0.087234</td>
      <td>496.910773</td>
      <td>5696.320517</td>
    </tr>
    <tr>
      <th>2017-10-20 08:56:00</th>
      <td>5690.88</td>
      <td>5690.88</td>
      <td>5690.88</td>
      <td>5690.88</td>
      <td>0.168941</td>
      <td>961.421706</td>
      <td>5690.880000</td>
    </tr>
    <tr>
      <th>2017-10-20 08:57:00</th>
      <td>5698.13</td>
      <td>5704.10</td>
      <td>5695.63</td>
      <td>5704.10</td>
      <td>2.311662</td>
      <td>13174.852877</td>
      <td>5699.300163</td>
    </tr>
    <tr>
      <th>2017-10-20 08:58:00</th>
      <td>5695.62</td>
      <td>5695.64</td>
      <td>5694.00</td>
      <td>5695.64</td>
      <td>0.129647</td>
      <td>738.409647</td>
      <td>5695.533637</td>
    </tr>
    <tr>
      <th>2017-10-20 08:59:00</th>
      <td>5700.39</td>
      <td>5700.39</td>
      <td>5698.69</td>
      <td>5698.69</td>
      <td>0.085426</td>
      <td>486.929798</td>
      <td>5700.004031</td>
    </tr>
    <tr>
      <th>2017-10-20 09:00:00</th>
      <td>5700.00</td>
      <td>5700.00</td>
      <td>5698.68</td>
      <td>5700.00</td>
      <td>0.116847</td>
      <td>665.913860</td>
      <td>5699.046463</td>
    </tr>
  </tbody>
</table>
<p>61 rows × 7 columns</p>
</div>



## DataFrame で遊ぶ

### DataFrame.describe

```python
DataFrame.describe(percentiles=None, include=None, exclude=None)
```

要約統計量を出す


```python
df.describe()
```




<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>Open</th>
      <th>High</th>
      <th>Low</th>
      <th>Close</th>
      <th>Volume_(BTC)</th>
      <th>Volume_(Currency)</th>
      <th>Weighted_Price</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>count</th>
      <td>61.000000</td>
      <td>61.000000</td>
      <td>61.000000</td>
      <td>61.000000</td>
      <td>61.000000</td>
      <td>61.000000</td>
      <td>61.000000</td>
    </tr>
    <tr>
      <th>mean</th>
      <td>5711.347541</td>
      <td>5713.140164</td>
      <td>5709.262787</td>
      <td>5711.027541</td>
      <td>1.802100</td>
      <td>10285.950059</td>
      <td>5711.197041</td>
    </tr>
    <tr>
      <th>std</th>
      <td>9.889195</td>
      <td>10.505623</td>
      <td>9.408502</td>
      <td>10.106421</td>
      <td>5.847390</td>
      <td>33350.541325</td>
      <td>9.798496</td>
    </tr>
    <tr>
      <th>min</th>
      <td>5690.880000</td>
      <td>5690.880000</td>
      <td>5690.880000</td>
      <td>5690.880000</td>
      <td>0.007902</td>
      <td>45.090203</td>
      <td>5690.880000</td>
    </tr>
    <tr>
      <th>25%</th>
      <td>5703.900000</td>
      <td>5704.010000</td>
      <td>5702.430000</td>
      <td>5703.950000</td>
      <td>0.085426</td>
      <td>486.929798</td>
      <td>5703.873513</td>
    </tr>
    <tr>
      <th>50%</th>
      <td>5708.850000</td>
      <td>5710.570000</td>
      <td>5706.010000</td>
      <td>5708.840000</td>
      <td>0.306643</td>
      <td>1754.230240</td>
      <td>5709.005356</td>
    </tr>
    <tr>
      <th>75%</th>
      <td>5720.010000</td>
      <td>5722.810000</td>
      <td>5719.950000</td>
      <td>5720.410000</td>
      <td>1.068407</td>
      <td>6111.485975</td>
      <td>5720.186975</td>
    </tr>
    <tr>
      <th>max</th>
      <td>5728.990000</td>
      <td>5729.000000</td>
      <td>5728.990000</td>
      <td>5729.000000</td>
      <td>44.402299</td>
      <td>253201.252480</td>
      <td>5728.992486</td>
    </tr>
  </tbody>
</table>
</div>



### DataFrame.hist

```python
DataFrame.hist(data, column=None, by=None, grid=True, xlabelsize=None, xrot=None, ylabelsize=None, yrot=None, ax=None, sharex=False, sharey=False, figsize=None, layout=None, bins=10, **kwds)
```

ヒストグラムを描く


```python
df.hist()
```




    array([[<matplotlib.axes._subplots.AxesSubplot object at 0x114eb8d50>,
            <matplotlib.axes._subplots.AxesSubplot object at 0x1154aa890>,
            <matplotlib.axes._subplots.AxesSubplot object at 0x115528050>],
           [<matplotlib.axes._subplots.AxesSubplot object at 0x1155a8210>,
            <matplotlib.axes._subplots.AxesSubplot object at 0x11570b350>,
            <matplotlib.axes._subplots.AxesSubplot object at 0x11578e390>],
           [<matplotlib.axes._subplots.AxesSubplot object at 0x115812210>,
            <matplotlib.axes._subplots.AxesSubplot object at 0x11587f350>,
            <matplotlib.axes._subplots.AxesSubplot object at 0x115a031d0>]], dtype=object)




![output_23_1.png](https://qiita-image-store.s3.amazonaws.com/0/29618/67302e14-041c-1861-bfc8-e8309643003e.png)


### matplotlib.finance.candlestick2_ohlc

```
matplotlib.finance.candlestick2_ohlc(ax, opens, highs, lows, closes, width=4, colorup='k', colordown='r', alpha=0.75)
```

ローソク足チャートを描画する


```python
import matplotlib.finance as mpf
fig = plt.figure(figsize=(18, 9))
ax = plt.subplot(1, 1, 1)
ax.set_xlim([0, df.shape[0]])
import matplotlib.ticker as ticker
ax.xaxis.set_major_locator(ticker.MaxNLocator(6))
ax.xaxis.set_major_formatter(ticker.FuncFormatter(df.index))

def dateformatter(x, pos):
    try:
        return df.index[int(x)]
    except IndexError:
        return ''

ax.xaxis.set_major_formatter(ticker.FuncFormatter(dateformatter))
fig.autofmt_xdate()
mpf.candlestick2_ohlc(ax, df.Open, df.High, df.Low, df.Close, width=0.9, colorup='g', colordown='r')
plt.show()
```


![output_25_0.png](https://qiita-image-store.s3.amazonaws.com/0/29618/28f04995-1154-a066-d20e-7080e9593892.png)