import io
import base64


def df_to_b64(df):
    """
        Transform a pandas dataframe to base64 encoded bytes
    """

    mbuffer = io.BytesIO()
    df.to_msgpack(mbuffer)
    mbuffer.seek(0)
    b64_string = base64.b64encode(mbuffer.read())

    return b64_string.decode()