下面的代碼創建一個熊貓系列句法糖生成熊貓系列採用了分層多指標:對於具有多指標
import pandas as pd
number_of_classes = 3
number_of_price_brackets = 10
survival_table = pd.Series(
index = pd.MultiIndex.from_tuples(
[(gender,klass,fare)
for gender in range(2)
for klass in range(number_of_classes)
for fare in range(number_of_price_brackets)],
names=['Gender','Class','Price Bracket']
))
但是這種做法似乎有點「手動」。有沒有更漂亮的方式來生成survival_table
變量?