import base64


def get_table_download_link(df, href_text="Download csv file"):
    """Generates a link allowing the data in a given panda dataframe to be downloaded
    
    Parameters
    ----------
    df : `pandas.DataFrame`
      DataFrame to provide download link for
    href_text: `str`
      The link text to display 

    Returns
    -------
    `str` Url to download the file

    Thanks to godot63, see https://discuss.streamlit.io/t/how-to-download-file-in-streamlit/1806

    """
    csv = df.to_csv(index=True)
    b64 = base64.b64encode(csv.encode()).decode()  # some strings <-> bytes conversions necessary here
    href = f'<a href="data:file/csv;base64,{b64}">{href_text}</a>'

    return href