从 pandas 数据框创建 'presence-absence' 矩阵

Creating a 'presence-absence' matrix from a pandas dataframe

我有 pandas 数据框形式的数据,类似于 中描述的数据。 即:

Species     Site 
Panthera    A 
Panthera    B 
Panthera    C 
Neofelis    B 
Neofelis    D

我想像这样创建一个存在-不存在矩阵:

Site    Panthera    Neofelis
A          1           0
B          1           1
C          1           0
D          0           1

我将如何在 Python 中而不是在 R 中执行此操作?

>>> pd.crosstab(df['Site'], df['Species'])
Species  Neofelis  Panthera
Site
A               0         1
B               1         1
C               0         1
D               1         0