これだけ覚えておけばなんとかなるPandas

# これは何？
Pandasのチートシートです。ほぼ自分用メモ。最低限の行間を読める人向け。

# Pandasチートシート
## 基本データ操作
### 各種インポート
```py3
import pandas as pd
import matplotlib as matplotlib
import matplotlib.pyplot as plt
from IPython.display import display
%matplotlib inline
```

### データのロード
```python
data = pd.read_csv('https://gist.githubusercontent.com/kojim/0a47ed4258222b0541a42aa9fd7da906/raw/a5d6a1a527deec269697c5b2ddab4157184af4ff/civ4.csv')
data.head(5)
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ターン数</th>
      <th>指導者</th>
      <th>都市名</th>
      <th>金銭</th>
      <th>研究</th>
      <th>文化</th>
      <th>スパイ</th>
      <th>生産</th>
      <th>維持費</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>10.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>1.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>1</th>
      <td>0</td>
      <td>TXT_KEY_LEADER_WANGKON</td>
      <td>TXT_KEY_CITY_NAME_SEOUL</td>
      <td>0.0</td>
      <td>9.0</td>
      <td>2.0</td>
      <td>4.0</td>
      <td>2.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>2</th>
      <td>0</td>
      <td>TXT_KEY_LEADER_HAMMURABI</td>
      <td>TXT_KEY_CITY_NAME_BABYLON</td>
      <td>0.0</td>
      <td>9.0</td>
      <td>2.0</td>
      <td>4.0</td>
      <td>1.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>3</th>
      <td>0</td>
      <td>TXT_KEY_LEADER_PACAL</td>
      <td>TXT_KEY_CITY_NAME_MUTAL</td>
      <td>0.0</td>
      <td>9.0</td>
      <td>2.0</td>
      <td>4.0</td>
      <td>1.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>4</th>
      <td>0</td>
      <td>TXT_KEY_LEADER_SITTING_BULL</td>
      <td>TXT_KEY_CITY_NAME_CAHOKIA</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>2.0</td>
      <td>4.0</td>
      <td>1.0</td>
      <td>0.0</td>
    </tr>
  </tbody>
</table>
</div>

### 行の絞込み(行数)
```python
data.head(3)
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ターン数</th>
      <th>指導者</th>
      <th>都市名</th>
      <th>金銭</th>
      <th>研究</th>
      <th>文化</th>
      <th>スパイ</th>
      <th>生産</th>
      <th>維持費</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>10.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>1.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>1</th>
      <td>0</td>
      <td>TXT_KEY_LEADER_WANGKON</td>
      <td>TXT_KEY_CITY_NAME_SEOUL</td>
      <td>0.0</td>
      <td>9.0</td>
      <td>2.0</td>
      <td>4.0</td>
      <td>2.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>2</th>
      <td>0</td>
      <td>TXT_KEY_LEADER_HAMMURABI</td>
      <td>TXT_KEY_CITY_NAME_BABYLON</td>
      <td>0.0</td>
      <td>9.0</td>
      <td>2.0</td>
      <td>4.0</td>
      <td>1.0</td>
      <td>0.0</td>
    </tr>
  </tbody>
</table>
</div>

### 行の絞込み(値)
```python
data.query("指導者 == 'kojim' & 金銭 > 5").head(3)
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ターン数</th>
      <th>指導者</th>
      <th>都市名</th>
      <th>金銭</th>
      <th>研究</th>
      <th>文化</th>
      <th>スパイ</th>
      <th>生産</th>
      <th>維持費</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>654</th>
      <td>64</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>6.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>11.0</td>
      <td>1.0</td>
    </tr>
    <tr>
      <th>674</th>
      <td>65</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>6.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>11.0</td>
      <td>1.0</td>
    </tr>
    <tr>
      <th>695</th>
      <td>66</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>6.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>11.0</td>
      <td>1.0</td>
    </tr>
  </tbody>
</table>
</div>

### 列の抽出(Seriesの取得)
```python
data['ターン数'].head(3)
```
    0    0
    1    0
    2    0
    Name: ターン数, dtype: int64

### 列の絞込み
```python
data[['ターン数', '指導者']].head(3)
```
<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ターン数</th>
      <th>指導者</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0</td>
      <td>kojim</td>
    </tr>
    <tr>
      <th>1</th>
      <td>0</td>
      <td>TXT_KEY_LEADER_WANGKON</td>
    </tr>
    <tr>
      <th>2</th>
      <td>0</td>
      <td>TXT_KEY_LEADER_HAMMURABI</td>
    </tr>
  </tbody>
</table>
</div>

### 列データの演算
```python
(data['ターン数'] + 10).head(3)
```
    0    10
    1    10
    2    10
    Name: ターン数, dtype: int64

### 列の追加
```python
data['出力'] = data['研究'] + data['生産']
data.head(3)
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ターン数</th>
      <th>指導者</th>
      <th>都市名</th>
      <th>金銭</th>
      <th>研究</th>
      <th>文化</th>
      <th>スパイ</th>
      <th>生産</th>
      <th>維持費</th>
      <th>出力</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>10.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>1.0</td>
      <td>0.0</td>
      <td>11.0</td>
    </tr>
    <tr>
      <th>1</th>
      <td>0</td>
      <td>TXT_KEY_LEADER_WANGKON</td>
      <td>TXT_KEY_CITY_NAME_SEOUL</td>
      <td>0.0</td>
      <td>9.0</td>
      <td>2.0</td>
      <td>4.0</td>
      <td>2.0</td>
      <td>0.0</td>
      <td>11.0</td>
    </tr>
    <tr>
      <th>2</th>
      <td>0</td>
      <td>TXT_KEY_LEADER_HAMMURABI</td>
      <td>TXT_KEY_CITY_NAME_BABYLON</td>
      <td>0.0</td>
      <td>9.0</td>
      <td>2.0</td>
      <td>4.0</td>
      <td>1.0</td>
      <td>0.0</td>
      <td>10.0</td>
    </tr>
  </tbody>
</table>
</div>

### 行の連結
```python
data2 = pd.read_csv('https://gist.githubusercontent.com/kojim/0a47ed4258222b0541a42aa9fd7da906/raw/a5d6a1a527deec269697c5b2ddab4157184af4ff/civ4.csv')
data.append(data2, ignore_index=True).head(3)
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>スパイ</th>
      <th>ターン数</th>
      <th>出力</th>
      <th>指導者</th>
      <th>文化</th>
      <th>生産</th>
      <th>研究</th>
      <th>維持費</th>
      <th>都市名</th>
      <th>金銭</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>4.0</td>
      <td>0</td>
      <td>11.0</td>
      <td>kojim</td>
      <td>4.0</td>
      <td>1.0</td>
      <td>10.0</td>
      <td>0.0</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>1</th>
      <td>4.0</td>
      <td>0</td>
      <td>11.0</td>
      <td>TXT_KEY_LEADER_WANGKON</td>
      <td>2.0</td>
      <td>2.0</td>
      <td>9.0</td>
      <td>0.0</td>
      <td>TXT_KEY_CITY_NAME_SEOUL</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>2</th>
      <td>4.0</td>
      <td>0</td>
      <td>10.0</td>
      <td>TXT_KEY_LEADER_HAMMURABI</td>
      <td>2.0</td>
      <td>1.0</td>
      <td>9.0</td>
      <td>0.0</td>
      <td>TXT_KEY_CITY_NAME_BABYLON</td>
      <td>0.0</td>
    </tr>
  </tbody>
</table>
</div>

### 列の連結
```python
data3 = pd.DataFrame(
    {'都市名': ['TXT_KEY_CITY_NAME_ATHENS'],
     '都市名(日本語)': ['アテネ']})
data3
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>都市名</th>
      <th>都市名(日本語)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>アテネ</td>
    </tr>
  </tbody>
</table>
</div>

```python
pd.merge(data, data3, on='都市名', how='left').head(3)
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ターン数</th>
      <th>指導者</th>
      <th>都市名</th>
      <th>金銭</th>
      <th>研究</th>
      <th>文化</th>
      <th>スパイ</th>
      <th>生産</th>
      <th>維持費</th>
      <th>出力</th>
      <th>都市名(日本語)</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>0</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>10.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>1.0</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>アテネ</td>
    </tr>
    <tr>
      <th>1</th>
      <td>0</td>
      <td>TXT_KEY_LEADER_WANGKON</td>
      <td>TXT_KEY_CITY_NAME_SEOUL</td>
      <td>0.0</td>
      <td>9.0</td>
      <td>2.0</td>
      <td>4.0</td>
      <td>2.0</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>NaN</td>
    </tr>
    <tr>
      <th>2</th>
      <td>0</td>
      <td>TXT_KEY_LEADER_HAMMURABI</td>
      <td>TXT_KEY_CITY_NAME_BABYLON</td>
      <td>0.0</td>
      <td>9.0</td>
      <td>2.0</td>
      <td>4.0</td>
      <td>1.0</td>
      <td>0.0</td>
      <td>10.0</td>
      <td>NaN</td>
    </tr>
  </tbody>
</table>
</div>

## グルーピング
### 列の値を使用したグルーピング
```python
data.groupby('指導者').sum()
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ターン数</th>
      <th>金銭</th>
      <th>研究</th>
      <th>文化</th>
      <th>スパイ</th>
      <th>生産</th>
      <th>維持費</th>
      <th>出力</th>
    </tr>
    <tr>
      <th>指導者</th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>TXT_KEY_LEADER_BARBARIAN</th>
      <td>18676</td>
      <td>369.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>458.0</td>
      <td>302.0</td>
      <td>458.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_LEADER_GILGAMESH</th>
      <td>526136</td>
      <td>22768.0</td>
      <td>57690.0</td>
      <td>40047.0</td>
      <td>30305.0</td>
      <td>32826.0</td>
      <td>5139.0</td>
      <td>90516.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_LEADER_HAMMURABI</th>
      <td>276530</td>
      <td>4612.0</td>
      <td>29905.0</td>
      <td>14777.0</td>
      <td>10738.0</td>
      <td>14424.0</td>
      <td>2280.0</td>
      <td>44329.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_LEADER_PACAL</th>
      <td>463715</td>
      <td>28303.0</td>
      <td>110795.0</td>
      <td>46527.0</td>
      <td>31253.0</td>
      <td>32673.0</td>
      <td>5193.0</td>
      <td>143468.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_LEADER_RAGNAR</th>
      <td>459257</td>
      <td>26257.0</td>
      <td>53257.0</td>
      <td>20919.0</td>
      <td>21955.0</td>
      <td>28830.0</td>
      <td>5826.0</td>
      <td>82087.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_LEADER_SITTING_BULL</th>
      <td>284044</td>
      <td>12073.0</td>
      <td>53986.0</td>
      <td>20733.0</td>
      <td>24190.0</td>
      <td>27457.0</td>
      <td>1580.0</td>
      <td>81443.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_LEADER_WANGKON</th>
      <td>356335</td>
      <td>13491.0</td>
      <td>60699.0</td>
      <td>25940.0</td>
      <td>25531.0</td>
      <td>24785.0</td>
      <td>2938.0</td>
      <td>85484.0</td>
    </tr>
    <tr>
      <th>kojim</th>
      <td>469839</td>
      <td>32913.0</td>
      <td>223011.0</td>
      <td>94184.0</td>
      <td>31967.0</td>
      <td>95515.0</td>
      <td>13509.0</td>
      <td>318526.0</td>
    </tr>
  </tbody>
</table>
</div>

### 関数を使用したグルーピング

data.groupby(lambda x: '偶数ターン' if data.ix[x]['ターン数'] % 2 else '奇数ターン').sum()

```python
data.groupby(lambda x: '偶数ターン' if data.ix[x]['ターン数'] % 2 else '奇数ターン').sum()
```


<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ターン数</th>
      <th>金銭</th>
      <th>研究</th>
      <th>文化</th>
      <th>スパイ</th>
      <th>生産</th>
      <th>維持費</th>
      <th>出力</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>偶数ターン</th>
      <td>1431876</td>
      <td>70479.0</td>
      <td>295597.0</td>
      <td>132280.0</td>
      <td>88755.0</td>
      <td>128240.0</td>
      <td>18415.0</td>
      <td>423837.0</td>
    </tr>
    <tr>
      <th>奇数ターン</th>
      <td>1422656</td>
      <td>70307.0</td>
      <td>293746.0</td>
      <td>130847.0</td>
      <td>87184.0</td>
      <td>128728.0</td>
      <td>18352.0</td>
      <td>422474.0</td>
    </tr>
  </tbody>
</table>
</div>


### 階層グルーピング
```python
g = data.groupby(['指導者', '都市名']).sum()
g.head(10)
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th></th>
      <th>ターン数</th>
      <th>金銭</th>
      <th>研究</th>
      <th>文化</th>
      <th>スパイ</th>
      <th>生産</th>
      <th>維持費</th>
      <th>出力</th>
    </tr>
    <tr>
      <th>指導者</th>
      <th>都市名</th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th rowspan="3" valign="top">TXT_KEY_LEADER_BARBARIAN</th>
      <th>TXT_KEY_CITY_NAME_KASSITE</th>
      <td>5481</td>
      <td>41.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>142.0</td>
      <td>60.0</td>
      <td>142.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_SAXON</th>
      <td>6825</td>
      <td>280.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>138.0</td>
      <td>121.0</td>
      <td>138.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_YAYOI</th>
      <td>6370</td>
      <td>48.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>178.0</td>
      <td>121.0</td>
      <td>178.0</td>
    </tr>
    <tr>
      <th rowspan="7" valign="top">TXT_KEY_LEADER_GILGAMESH</th>
      <th>TXT_KEY_CITY_NAME_BAD_TIBIRA</th>
      <td>55560</td>
      <td>1210.0</td>
      <td>2468.0</td>
      <td>1009.0</td>
      <td>980.0</td>
      <td>1938.0</td>
      <td>783.0</td>
      <td>4406.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_ERIDU</th>
      <td>61035</td>
      <td>4153.0</td>
      <td>9768.0</td>
      <td>5691.0</td>
      <td>3768.0</td>
      <td>4776.0</td>
      <td>423.0</td>
      <td>14544.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_KISH</th>
      <td>60291</td>
      <td>1319.0</td>
      <td>7374.0</td>
      <td>4118.0</td>
      <td>4591.0</td>
      <td>2480.0</td>
      <td>508.0</td>
      <td>9854.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_LAGASH</th>
      <td>58206</td>
      <td>1162.0</td>
      <td>1980.0</td>
      <td>5989.0</td>
      <td>3130.0</td>
      <td>3919.0</td>
      <td>424.0</td>
      <td>5899.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_NIBRU</th>
      <td>51623</td>
      <td>1571.0</td>
      <td>3397.0</td>
      <td>3242.0</td>
      <td>1000.0</td>
      <td>2347.0</td>
      <td>757.0</td>
      <td>5744.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_NIPPUR</th>
      <td>32093</td>
      <td>215.0</td>
      <td>526.0</td>
      <td>1243.0</td>
      <td>756.0</td>
      <td>1836.0</td>
      <td>349.0</td>
      <td>2362.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_SAXON</th>
      <td>39831</td>
      <td>575.0</td>
      <td>1984.0</td>
      <td>1485.0</td>
      <td>1309.0</td>
      <td>1133.0</td>
      <td>296.0</td>
      <td>3117.0</td>
    </tr>
  </tbody>
</table>
</div>

Jupyterの表示上、指導者列は2行しかないように見えるが、表示上そうなっているだけで、実際には行の数、つまり↑の例で言えば10行存在する。以下のようにすることでそれは確認できる。

```python
g.head(10).index.values
```

    array([('TXT_KEY_LEADER_BARBARIAN', 'TXT_KEY_CITY_NAME_KASSITE'),
       ('TXT_KEY_LEADER_BARBARIAN', 'TXT_KEY_CITY_NAME_SAXON'),
       ('TXT_KEY_LEADER_BARBARIAN', 'TXT_KEY_CITY_NAME_YAYOI'),
       ('TXT_KEY_LEADER_GILGAMESH', 'TXT_KEY_CITY_NAME_BAD_TIBIRA'),
       ('TXT_KEY_LEADER_GILGAMESH', 'TXT_KEY_CITY_NAME_ERIDU'),
       ('TXT_KEY_LEADER_GILGAMESH', 'TXT_KEY_CITY_NAME_KISH'),
       ('TXT_KEY_LEADER_GILGAMESH', 'TXT_KEY_CITY_NAME_LAGASH'),
       ('TXT_KEY_LEADER_GILGAMESH', 'TXT_KEY_CITY_NAME_NIBRU'),
       ('TXT_KEY_LEADER_GILGAMESH', 'TXT_KEY_CITY_NAME_NIPPUR'),
       ('TXT_KEY_LEADER_GILGAMESH', 'TXT_KEY_CITY_NAME_SAXON')], dtype=object)

### 階層グループの階層入れ替え

つまり入れ替えることもできる。

```python
g.swaplevel(0, 1).head(10)
```
<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th></th>
      <th>ターン数</th>
      <th>金銭</th>
      <th>研究</th>
      <th>文化</th>
      <th>スパイ</th>
      <th>生産</th>
      <th>維持費</th>
      <th>出力</th>
    </tr>
    <tr>
      <th>都市名</th>
      <th>指導者</th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>TXT_KEY_CITY_NAME_KASSITE</th>
      <th>TXT_KEY_LEADER_BARBARIAN</th>
      <td>5481</td>
      <td>41.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>142.0</td>
      <td>60.0</td>
      <td>142.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_SAXON</th>
      <th>TXT_KEY_LEADER_BARBARIAN</th>
      <td>6825</td>
      <td>280.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>138.0</td>
      <td>121.0</td>
      <td>138.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_YAYOI</th>
      <th>TXT_KEY_LEADER_BARBARIAN</th>
      <td>6370</td>
      <td>48.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>0.0</td>
      <td>178.0</td>
      <td>121.0</td>
      <td>178.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_BAD_TIBIRA</th>
      <th>TXT_KEY_LEADER_GILGAMESH</th>
      <td>55560</td>
      <td>1210.0</td>
      <td>2468.0</td>
      <td>1009.0</td>
      <td>980.0</td>
      <td>1938.0</td>
      <td>783.0</td>
      <td>4406.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_ERIDU</th>
      <th>TXT_KEY_LEADER_GILGAMESH</th>
      <td>61035</td>
      <td>4153.0</td>
      <td>9768.0</td>
      <td>5691.0</td>
      <td>3768.0</td>
      <td>4776.0</td>
      <td>423.0</td>
      <td>14544.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_KISH</th>
      <th>TXT_KEY_LEADER_GILGAMESH</th>
      <td>60291</td>
      <td>1319.0</td>
      <td>7374.0</td>
      <td>4118.0</td>
      <td>4591.0</td>
      <td>2480.0</td>
      <td>508.0</td>
      <td>9854.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_LAGASH</th>
      <th>TXT_KEY_LEADER_GILGAMESH</th>
      <td>58206</td>
      <td>1162.0</td>
      <td>1980.0</td>
      <td>5989.0</td>
      <td>3130.0</td>
      <td>3919.0</td>
      <td>424.0</td>
      <td>5899.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_NIBRU</th>
      <th>TXT_KEY_LEADER_GILGAMESH</th>
      <td>51623</td>
      <td>1571.0</td>
      <td>3397.0</td>
      <td>3242.0</td>
      <td>1000.0</td>
      <td>2347.0</td>
      <td>757.0</td>
      <td>5744.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_NIPPUR</th>
      <th>TXT_KEY_LEADER_GILGAMESH</th>
      <td>32093</td>
      <td>215.0</td>
      <td>526.0</td>
      <td>1243.0</td>
      <td>756.0</td>
      <td>1836.0</td>
      <td>349.0</td>
      <td>2362.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_SAXON</th>
      <th>TXT_KEY_LEADER_GILGAMESH</th>
      <td>39831</td>
      <td>575.0</td>
      <td>1984.0</td>
      <td>1485.0</td>
      <td>1309.0</td>
      <td>1133.0</td>
      <td>296.0</td>
      <td>3117.0</td>
    </tr>
  </tbody>
</table>
<p>10 rows × 8 columns</p>
</div>

### 階層グループの再並び替え

入れ替えた後並び替えることもできる。

```python
g.swaplevel(0, 1).sortlevel(0).head(3)
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th></th>
      <th>ターン数</th>
      <th>金銭</th>
      <th>研究</th>
      <th>文化</th>
      <th>スパイ</th>
      <th>生産</th>
      <th>維持費</th>
      <th>出力</th>
    </tr>
    <tr>
      <th>都市名</th>
      <th>指導者</th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th rowspan="3" valign="top">TXT_KEY_CITY_NAME_AKKAD</th>
      <th>TXT_KEY_LEADER_HAMMURABI</th>
      <td>16769</td>
      <td>153.0</td>
      <td>936.0</td>
      <td>744.0</td>
      <td>29.0</td>
      <td>638.0</td>
      <td>287.0</td>
      <td>1574.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_LEADER_RAGNAR</th>
      <td>41110</td>
      <td>1631.0</td>
      <td>2496.0</td>
      <td>776.0</td>
      <td>977.0</td>
      <td>1782.0</td>
      <td>590.0</td>
      <td>4278.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_LEADER_WANGKON</th>
      <td>3492</td>
      <td>44.0</td>
      <td>55.0</td>
      <td>128.0</td>
      <td>12.0</td>
      <td>144.0</td>
      <td>57.0</td>
      <td>199.0</td>
    </tr>
  </tbody>
</table>
</div>

### 階層グループをピボットテーブル形式に再構成する




```python
g2 = g[['出力']].head(3)
g2
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th></th>
      <th>出力</th>
    </tr>
    <tr>
      <th>指導者</th>
      <th>都市名</th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th rowspan="3" valign="top">TXT_KEY_LEADER_BARBARIAN</th>
      <th>TXT_KEY_CITY_NAME_KASSITE</th>
      <td>142.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_SAXON</th>
      <td>138.0</td>
    </tr>
    <tr>
      <th>TXT_KEY_CITY_NAME_YAYOI</th>
      <td>178.0</td>
    </tr>
  </tbody>
</table>
</div>

```python
g2.unstack()
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr>
      <th></th>
      <th colspan="3" halign="left">出力</th>
    </tr>
    <tr>
      <th>都市名</th>
      <th>TXT_KEY_CITY_NAME_KASSITE</th>
      <th>TXT_KEY_CITY_NAME_SAXON</th>
      <th>TXT_KEY_CITY_NAME_YAYOI</th>
    </tr>
    <tr>
      <th>指導者</th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>TXT_KEY_LEADER_BARBARIAN</th>
      <td>142.0</td>
      <td>138.0</td>
      <td>178.0</td>
    </tr>
  </tbody>
</table>
</div>

### 列全体の集計
データの下準備

```python
data3 = data.query("指導者 == 'kojim' & ターン数 > 40 & ターン数 < 50")
data3
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ターン数</th>
      <th>指導者</th>
      <th>都市名</th>
      <th>金銭</th>
      <th>研究</th>
      <th>文化</th>
      <th>スパイ</th>
      <th>生産</th>
      <th>維持費</th>
      <th>出力</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>299</th>
      <td>41</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>12.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>8.0</td>
      <td>0.0</td>
      <td>20.0</td>
    </tr>
    <tr>
      <th>311</th>
      <td>42</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>10.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>11.0</td>
      <td>0.0</td>
      <td>21.0</td>
    </tr>
    <tr>
      <th>323</th>
      <td>43</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
    </tr>
    <tr>
      <th>335</th>
      <td>44</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
    </tr>
    <tr>
      <th>348</th>
      <td>45</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
    </tr>
    <tr>
      <th>361</th>
      <td>46</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
    </tr>
    <tr>
      <th>362</th>
      <td>46</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_SPARTA</td>
      <td>0.0</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>0.0</td>
      <td>2.0</td>
      <td>2.0</td>
      <td>3.0</td>
    </tr>
    <tr>
      <th>375</th>
      <td>47</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
    </tr>
    <tr>
      <th>376</th>
      <td>47</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_SPARTA</td>
      <td>0.0</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>0.0</td>
      <td>2.0</td>
      <td>2.0</td>
      <td>3.0</td>
    </tr>
    <tr>
      <th>389</th>
      <td>48</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
    </tr>
    <tr>
      <th>390</th>
      <td>48</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_SPARTA</td>
      <td>0.0</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>0.0</td>
      <td>2.0</td>
      <td>2.0</td>
      <td>3.0</td>
    </tr>
    <tr>
      <th>403</th>
      <td>49</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>8.0</td>
      <td>0.0</td>
      <td>19.0</td>
    </tr>
    <tr>
      <th>404</th>
      <td>49</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_SPARTA</td>
      <td>0.0</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>0.0</td>
      <td>2.0</td>
      <td>2.0</td>
      <td>3.0</td>
    </tr>
  </tbody>
</table>
</div>

列全体の累積値を計算。

```python
data3['累積出力'] = data['出力'].cumsum()
data3
```
<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>ターン数</th>
      <th>指導者</th>
      <th>都市名</th>
      <th>金銭</th>
      <th>研究</th>
      <th>文化</th>
      <th>スパイ</th>
      <th>生産</th>
      <th>維持費</th>
      <th>出力</th>
      <th>累積出力</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>299</th>
      <td>41</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>12.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>8.0</td>
      <td>0.0</td>
      <td>20.0</td>
      <td>3419.0</td>
    </tr>
    <tr>
      <th>311</th>
      <td>42</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>10.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>11.0</td>
      <td>0.0</td>
      <td>21.0</td>
      <td>3545.0</td>
    </tr>
    <tr>
      <th>323</th>
      <td>43</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
      <td>3666.0</td>
    </tr>
    <tr>
      <th>335</th>
      <td>44</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
      <td>3786.0</td>
    </tr>
    <tr>
      <th>348</th>
      <td>45</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
      <td>3908.0</td>
    </tr>
    <tr>
      <th>361</th>
      <td>46</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
      <td>4031.0</td>
    </tr>
    <tr>
      <th>362</th>
      <td>46</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_SPARTA</td>
      <td>0.0</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>0.0</td>
      <td>2.0</td>
      <td>2.0</td>
      <td>3.0</td>
      <td>4034.0</td>
    </tr>
    <tr>
      <th>375</th>
      <td>47</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
      <td>4164.0</td>
    </tr>
    <tr>
      <th>376</th>
      <td>47</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_SPARTA</td>
      <td>0.0</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>0.0</td>
      <td>2.0</td>
      <td>2.0</td>
      <td>3.0</td>
      <td>4167.0</td>
    </tr>
    <tr>
      <th>389</th>
      <td>48</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
      <td>4295.0</td>
    </tr>
    <tr>
      <th>390</th>
      <td>48</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_SPARTA</td>
      <td>0.0</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>0.0</td>
      <td>2.0</td>
      <td>2.0</td>
      <td>3.0</td>
      <td>4298.0</td>
    </tr>
    <tr>
      <th>403</th>
      <td>49</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_ATHENS</td>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>8.0</td>
      <td>0.0</td>
      <td>19.0</td>
      <td>4428.0</td>
    </tr>
    <tr>
      <th>404</th>
      <td>49</td>
      <td>kojim</td>
      <td>TXT_KEY_CITY_NAME_SPARTA</td>
      <td>0.0</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>0.0</td>
      <td>2.0</td>
      <td>2.0</td>
      <td>3.0</td>
      <td>4431.0</td>
    </tr>
  </tbody>
</table>
</div>

列全体の合計値を計算。

```python
data['出力'].sum()
```

### グループごとの再集計
```python
data4 = data.query("指導者 == 'kojim' & ターン数 > 40 & ターン数 < 50").groupby(['都市名', 'ターン数']).sum()
data4
```

たとえば階層データの特定階層での集計を行いたい場合。

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th></th>
      <th>金銭</th>
      <th>研究</th>
      <th>文化</th>
      <th>スパイ</th>
      <th>生産</th>
      <th>維持費</th>
      <th>出力</th>
    </tr>
    <tr>
      <th>都市名</th>
      <th>ターン数</th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th rowspan="9" valign="top">TXT_KEY_CITY_NAME_ATHENS</th>
      <th>41</th>
      <td>0.0</td>
      <td>12.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>8.0</td>
      <td>0.0</td>
      <td>20.0</td>
    </tr>
    <tr>
      <th>42</th>
      <td>0.0</td>
      <td>10.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>11.0</td>
      <td>0.0</td>
      <td>21.0</td>
    </tr>
    <tr>
      <th>43</th>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
    </tr>
    <tr>
      <th>44</th>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
    </tr>
    <tr>
      <th>45</th>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
    </tr>
    <tr>
      <th>46</th>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
    </tr>
    <tr>
      <th>47</th>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
    </tr>
    <tr>
      <th>48</th>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>7.0</td>
      <td>0.0</td>
      <td>18.0</td>
    </tr>
    <tr>
      <th>49</th>
      <td>0.0</td>
      <td>11.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>8.0</td>
      <td>0.0</td>
      <td>19.0</td>
    </tr>
    <tr>
      <th rowspan="4" valign="top">TXT_KEY_CITY_NAME_SPARTA</th>
      <th>46</th>
      <td>0.0</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>0.0</td>
      <td>2.0</td>
      <td>2.0</td>
      <td>3.0</td>
    </tr>
    <tr>
      <th>47</th>
      <td>0.0</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>0.0</td>
      <td>2.0</td>
      <td>2.0</td>
      <td>3.0</td>
    </tr>
    <tr>
      <th>48</th>
      <td>0.0</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>0.0</td>
      <td>2.0</td>
      <td>2.0</td>
      <td>3.0</td>
    </tr>
    <tr>
      <th>49</th>
      <td>0.0</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>0.0</td>
      <td>2.0</td>
      <td>2.0</td>
      <td>3.0</td>
    </tr>
  </tbody>
</table>
</div>

```python
data4.groupby(level=0).cumsum()
```

<div>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th></th>
      <th>スパイ</th>
      <th>出力</th>
      <th>文化</th>
      <th>生産</th>
      <th>研究</th>
      <th>維持費</th>
      <th>金銭</th>
    </tr>
    <tr>
      <th>都市名</th>
      <th>ターン数</th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th rowspan="9" valign="top">TXT_KEY_CITY_NAME_ATHENS</th>
      <th>41</th>
      <td>4.0</td>
      <td>20.0</td>
      <td>4.0</td>
      <td>8.0</td>
      <td>12.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>42</th>
      <td>8.0</td>
      <td>41.0</td>
      <td>8.0</td>
      <td>19.0</td>
      <td>22.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>43</th>
      <td>12.0</td>
      <td>59.0</td>
      <td>12.0</td>
      <td>26.0</td>
      <td>33.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>44</th>
      <td>16.0</td>
      <td>77.0</td>
      <td>16.0</td>
      <td>33.0</td>
      <td>44.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>45</th>
      <td>20.0</td>
      <td>95.0</td>
      <td>20.0</td>
      <td>40.0</td>
      <td>55.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>46</th>
      <td>24.0</td>
      <td>113.0</td>
      <td>24.0</td>
      <td>47.0</td>
      <td>66.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>47</th>
      <td>28.0</td>
      <td>131.0</td>
      <td>28.0</td>
      <td>54.0</td>
      <td>77.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>48</th>
      <td>32.0</td>
      <td>149.0</td>
      <td>32.0</td>
      <td>61.0</td>
      <td>88.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>49</th>
      <td>36.0</td>
      <td>168.0</td>
      <td>36.0</td>
      <td>69.0</td>
      <td>99.0</td>
      <td>0.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th rowspan="4" valign="top">TXT_KEY_CITY_NAME_SPARTA</th>
      <th>46</th>
      <td>0.0</td>
      <td>3.0</td>
      <td>2.0</td>
      <td>2.0</td>
      <td>1.0</td>
      <td>2.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>47</th>
      <td>0.0</td>
      <td>6.0</td>
      <td>4.0</td>
      <td>4.0</td>
      <td>2.0</td>
      <td>4.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>48</th>
      <td>0.0</td>
      <td>9.0</td>
      <td>6.0</td>
      <td>6.0</td>
      <td>3.0</td>
      <td>6.0</td>
      <td>0.0</td>
    </tr>
    <tr>
      <th>49</th>
      <td>0.0</td>
      <td>12.0</td>
      <td>8.0</td>
      <td>8.0</td>
      <td>4.0</td>
      <td>8.0</td>
      <td>0.0</td>
    </tr>
  </tbody>
</table>
</div>