【11-1】
▲Dataframe関数
--------------
>>> import pandas as pd
>>> data = {
...     'name': ['Max', 'Oscar', 'Milo', 'Charlie', 'Buddy'],
...     'weight': [72, 69, 68, 64, 58],
...     'height': [178, 173, 169, 165, 162]
...     }
>>> df = pd.DataFrame(data)
>>> print(df)
      name weight  height
0      Max     72     178
1    Oscar     69     173
2     Milo     68     169
3  Charlie     64     165
4    Buddy     58     162
>>> print(df.dtypes)
name      object
weight     int64
height     int64
dtype: object
>>> print(df.columns)
Index(['name', 'weight', 'height'], dtype='object')
>>> print(df.index)
RangeIndex(start=0, stop=5, step=1)
--------------


【11-2】
▲sort_value関数
--------------
>>> import pandas as pd
>>> import numpy as np
>>> df = pd.DataFrame(np.random.randn(5,1))
>>> df.sort_values(by=0)
          0
4 -0.832229
1 -0.359766
2  0.099690
3  0.283921
0  0.541515
>>> df.sort_values(by=0, ascending=False)
          0
0  0.541515
3  0.283921
2  0.099690
1 -0.359766
4 -0.832229
--------------


【11-3】
▲head/tail関数
--------------
>>> import pandas as pd
>>> data = {
...      'name': ['Max', 'Oscar', 'Milo', 'Charlie', 'Buddy'],
...      'weight': [72, 69, 68, 64, 58],
...      'height': [178, 173, 169, 165, 162]
...      }
>>> df = pd.DataFrame(data)
>>> print(df)
      name weight  height
0      Max     72     178
1    Oscar     69     173
2     Milo     68     169
3  Charlie     64     165
4    Buddy     58     162
>>> df.head(2)
    name weight  height
0    Max     72     178
1  Oscar     69     173
>>> df.tail(3)
      name weight  height
2     Milo     68     169
3  Charlie     64     165
4    Buddy     58     162
>>> df.head(2).append(df.tail(2))
      name weight  height
0      Max     72     178
1    Oscar     69     173
3  Charlie     64     165
4    Buddy     58     162
--------------


【11-4】
▲loc/iloc関数
--------------
>>> import pandas as pd
>>> data = {
...      'name': ['Max', 'Oscar', 'Milo', 'Charlie', 'Buddy'],
...      'weight': [72, 69, 68, 64, 58],
...      'height': [178, 173, 169, 165, 162]
...      }
>>> df = pd.DataFrame(data)
>>> print(df)
      name weight  height
0      Max     72     178
1    Oscar     69     173
2     Milo     68     169
3  Charlie     64     165
4    Buddy     58     162
>>> df.loc[:, 'name']
0        Max
1      Oscar
2       Milo
3    Charlie
4      Buddy
Name: name, dtype: object
>>> df.loc[:, ['name', 'height']]
      name  height
0      Max     178
1    Oscar     173
2     Milo     169
3  Charlie     165
4    Buddy     162
>>> df.loc[1:3, :]
      name weight  height
1    Oscar     69     173
2     Milo     68     169
3  Charlie     64     165
>>> df.iloc[2:4]
      name weight  height
2     Milo     68     169
3  Charlie     64     165
>>> df.iloc[1:3, 0:2]
    name weight
1  Oscar     69
2   Milo     68
--------------


【11-5】
▲query関数
--------------
>>> import pandas as pd
>>> data = {
...      'name': ['Max', 'Oscar', 'Milo', 'Charlie', 'Buddy'],
...      'weight': [72, 69, 68, 64, 58],
...      'height': [178, 173, 169, 165, 162]
...      }
>>> df = pd.DataFrame(data)
>>> print(df)
      name  weight  height
0      Max      72     178
1    Oscar      69     173
2     Milo      68     169
3  Charlie      64     165
4    Buddy      58     162
>>> df.query('name == "Milo"')
   name weight  height
2  Milo     68     169
>>> df.query('weight <= 68')
      name  weight  height
2     Milo      68     169
3  Charlie      64     165
4    Buddy      58     162
>>> df.query('weight < 70 and height > 165')
    name  weight  height
1  Oscar      69     173
2   Milo      68     169
>>> df.query('weight <  height - 101')
    name  weight  height
0    Max      72     178
1  Oscar      69     173
4  Buddy      58     162
--------------


【11-6】
▲CSVファイルの読み出し
--------------
>>> import pandas as pd
>>> data = {'clo1': [0.1, 0.2], 'col2': [0.3, 0.4], 'col3': [0.5, 0.6]}
>>> df = pd.DataFrame(data)
>>> print(df)
   clo1  col2  col3
0   0.1   0.3   0.5
1   0.2   0.4   0.6
>>> df.to_csv('output.csv')
>>> data = pd.read_csv('output.csv')
>>> print(data)
   Unnamed: 0  clo1  col2  col3
0           0   0.1   0.3   0.5
1           1   0.2   0.4   0.6
--------------