「縦:年齢」 × 「横:性別」のような1列 × 1列のピポットテーブルを発展させて、
「縦:年齢、居住地」 × 「横:性別、既婚未婚」のようなn列 × m列のピポットテーブルも作成する機会があると思います。
以下、例です。

元データ:adult.csv

In [1]: import pandas as pd
   ...: data1 = pd.read_csv("adult.csv")
   ...: data1.head()
   ...:
Out[1]:
   age  workclass  fnlwgt     education  educational-num      marital-status  \
0   25    Private  226802          11th                7       Never-married
1   38    Private   89814       HS-grad                9  Married-civ-spouse
2   28  Local-gov  336951    Assoc-acdm               12  Married-civ-spouse
3   44    Private  160323  Some-college               10  Married-civ-spouse
4   18          ?  103497  Some-college               10       Never-married

          occupation relationship   race  gender  capital-gain  capital-loss  \
0  Machine-op-inspct    Own-child  Black    Male             0             0
1    Farming-fishing      Husband  White    Male             0             0
2    Protective-serv      Husband  White    Male             0             0
3  Machine-op-inspct      Husband  Black    Male          7688             0
4                  ?    Own-child  White  Female             0             0

   hours-per-week native-country income
0              40  United-States  <=50K
1              50  United-States  <=50K 2 40 United-States >50K
3              40  United-States   >50K
4              30  United-States  <=50K

indexパラメータとcolumnsパラメータに配列を渡します。

# 'race', 'relationship'を縦に残し、'gender', 'workclass'を横に展開する
pivot_data = pd.pivot_table(data1,
    index = ['race', 'relationship'],
    columns = ['gender', 'workclass'],
    values = 'capital-gain',
    aggfunc = 'mean',
    fill_value = 0
)

少し見づらいですが、結果は以下の通り。

Out[49]:
gender                            Female                                       \
workclass                              ? Federal-gov   Local-gov Never-worked
race               relationship
Amer-Indian-Eskimo Husband           0.0         0.0    0.000000            0
                   Not-in-family     0.0         0.0  415.625000            0
                   Other-relative    0.0         0.0    0.000000            0
                   Own-child       594.0         0.0    0.000000            0
                   Unmarried         0.0         0.0  330.777778            0

gender                                                                       \
workclass                             Private Self-emp-inc Self-emp-not-inc
race               relationship
Amer-Indian-Eskimo Husband           0.000000          0.0              0.0
                   Not-in-family   631.035714          0.0              0.0
                   Other-relative    0.000000          0.0              0.0
                   Own-child       231.764706          0.0              0.0
                   Unmarried       180.236842          0.0              0.0

gender                                                      Male              \
workclass                         State-gov Without-pay        ? Federal-gov
race               relationship
Amer-Indian-Eskimo Husband              0.0           0  1403.75         0.0
                   Not-in-family        0.0           0     0.00         0.0
                   Other-relative       0.0           0     0.00         0.0
                   Own-child            0.0           0     0.00         0.0
                   Unmarried            0.0           0     0.00         0.0

gender                                                                 \
workclass                         Local-gov Never-worked      Private
race               relationship
Amer-Indian-Eskimo Husband              0.0            0   482.666667
                   Not-in-family        0.0            0  1189.804348
                   Other-relative       0.0            0  3092.000000
                   Own-child          930.0            0  1380.518519
                   Unmarried            0.0            0     0.000000

gender                                                                     \
workclass                         Self-emp-inc Self-emp-not-inc State-gov
race               relationship
Amer-Indian-Eskimo Husband              2885.0       569.736842       0.0
                   Not-in-family           0.0         0.000000       0.0
                   Other-relative          0.0         0.000000       0.0
                   Own-child               0.0         0.000000       0.0
                   Unmarried               0.0         0.000000       0.0

gender
workclass                         Without-pay
race               relationship
Amer-Indian-Eskimo Husband                0.0
                   Not-in-family          0.0
                   Other-relative         0.0
                   Own-child              0.0
                   Unmarried              0.0

pythonの集計は、見やすいように、と配慮してくれているのか、行列形式でデータを見たいユーザーとしては、少し不便です。
次の記事で見やすいように調整してみたいと思います。