Calculates an empirical intra-specific spatial abundance distribution

    Parameters
    ----------
    {0}

    Returns
    -------
    {1} Result has one column giving the individuals of species in each
    subplot.

    Notes
    -----
    {2}

    {3}

    Examples
    --------

    {4}

    >>> # Get the spatial abundance distribution for all species for each of
    >>> # the cells in the ANBO plot
    >>> all_spp_ssads = meco.empirical.ssad(pat, cols='spp_col:spp; count_col:count', splits='row:4; column:4')

    >>> # Convert to dict for easy searching
    >>> all_ssads_dict = dict(all_spp_ssads)

    >>> # Look up the spatial abundance distribution for 'grass'
    >>> all_ssads_dict['grass']
         y
    0    42
    1    20
    2    60
    3    60
    4    88
    5    86
    6    20
    7     0
    8   110
    9    12
    10  115
    11  180
    12  160
    13  120
    14   26
    15   11

    >>> # Each value in 'y' gives the abundance of grass in one of the 16 cells

    See http://www.macroeco.org/tutorial_macroeco.html for additional
    examples and explanation

def ssad(patch, cols, splits):
    """
    Calculates an empirical intra-specific spatial abundance distribution

    Parameters
    ----------
    {0}

    Returns
    -------
    {1} Result has one column giving the individuals of species in each
    subplot.

    Notes
    -----
    {2}

    {3}

    Examples
    --------

    {4}

    >>> # Get the spatial abundance distribution for all species for each of
    >>> # the cells in the ANBO plot
    >>> all_spp_ssads = meco.empirical.ssad(pat, cols='spp_col:spp; count_col:count', splits='row:4; column:4')

    >>> # Convert to dict for easy searching
    >>> all_ssads_dict = dict(all_spp_ssads)

    >>> # Look up the spatial abundance distribution for 'grass'
    >>> all_ssads_dict['grass']
         y
    0    42
    1    20
    2    60
    3    60
    4    88
    5    86
    6    20
    7     0
    8   110
    9    12
    10  115
    11  180
    12  160
    13  120
    14   26
    15   11

    >>> # Each value in 'y' gives the abundance of grass in one of the 16 cells

    See http://www.macroeco.org/tutorial_macroeco.html for additional
    examples and explanation

    """

    # Get and check SAD
    sad_results = sad(patch, cols, splits, clean=False)

    # Create dataframe with col for spp name and numbered col for each split
    for i, sad_result in enumerate(sad_results):
        if i == 0:  # For first result, create dataframe
            fulldf = sad_result[1]
            fulldf.columns = ['spp', '0']  # Renames y col to 0
        else:  # For other results, append col to dataframe, named by num
            fulldf[str(i)] = sad_result[1]['y']

    # Get each spp SSAD (row of fulldf) and append as tuple in result_list
    result_list = []
    for _, row in fulldf.iterrows():
        row_values_array = np.array(row[1:], dtype=float)
        result_list.append((row[0], pd.DataFrame({'y': row_values_array})))

    # Return all results
    return result_list