DFWidget

In [1]:

    from df_cereal.df_widget import DFWidget, BaseWidget
    import pandas as pd

In [2]:

    df = pd.DataFrame({'a':[10,50], 'b': ['paddy', 'margaret']})
    DFWidget(df)

Out[2]:
In [3]:

    from traitlets import Unicode, List, Dict, observe, Any, Bytes

    class Base64Widget(BaseWidget):
        _view_name = Unicode('Base64WidgetView').tag(sync=True)
        df_base64 = Any("").tag(sync=True)

    class BytesWidget(BaseWidget):
        _view_name = Unicode('BytesWidgetView').tag(sync=True)
        df_arrow_bytes = Bytes().tag(sync=True)

In [4]:

    base64table = "/////zgBAAAQAAAAAAAKABAADgAHAAgACgAAAAAAAAEIAAAAAAAEAHz///8EAAAABAAAANgAAACYAAAARAAAAAQAAABI////FAAAAAAAAAEUAAAAAAAAAxAAAAABAAAAZAAAAAAAAAA2////AAACABAAHAAIAA8AFwAYAAQAEAAQAAAAMAAAABQAAAAAAAABFAAAAAAAAAUQAAAAAQAAAGMAAAAAAAAAtP///wgACAAAAAQACAAAAAwAAAAIAAwACAAHAAgAAAAAAAABIAAAANT///8UAAAAAAAAARQAAAAAAAAGFAAAAAEAAABiAAAAAAAAAAQABAAEAAAAEAAYAAQACwATABQAAAAMABAAAAAUAAAAAAAAARQAAAAAAAADGAAAAAEAAABhAAAAAAAAAAAABgAIAAYABgAAAAAAAgD/////sAAAABQAAAAAAAAADAAcABoAEwAUAAQADAAAABgAAAAAAAAAAAAAAAAAAAIQAAAAAAAEAAgACgAAAAQACAAAABAAAAAAAAoAGAAMAAgABAAKAAAAFAAAAEgAAAACAAAAAAAAAAAAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAQAAAAAAAAAAgAAAAAAAAAAAAAAAEAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAGAAAAAAAAAGZvb2JhcgAA/////xgBAAAUAAAAAAAAAAwAFgAUAA8AEAAEAAwAAABoAAAAAAAAAAAAAAMQAAAABAAKABgADAAIAAQACgAAABQAAACYAAAAAgAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAQAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAUAAAAAAAAAAIAAAAAAAAAFgAAAAAAAAAAAAAAAAAAABYAAAAAAAAABAAAAAAAAAAAAAAAAQAAAACAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAARUAAAAAAAAAoQAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAM3MzMzMzDfAMzMzMzMzIkD/////AAAAAA=="

In [5]:

    Base64Widget(df_base64=base64table)

Out[5]:
In [6]:

    import pyarrow as pa
    df = pd.DataFrame({'a':[10,50], 'b': ['paddy', 'margaret']})
    table = pa.Table.from_pandas(df)
    batches = table.to_batches()[0]
    pabuffer = batches.serialize()
    pabuffer.to_pybytes()[:30]

Out[6]:

    b'\xff\xff\xff\xff\xc8\x00\x00\x00\x14\x00\x00\x00\x00\x00\x00\x00\x0c\x00\x16\x00\x06\x00\x05\x00\x08\x00\x0c\x00\x0c\x00'

In [7]:

    BytesWidget(df_arrow_bytes=pabuffer.to_pybytes())

Out[7]:
In [8]:

    import base64
    b64_t2 = base64.b64encode(pabuffer.to_pybytes())
    #Base64Widget(df_base64=b64_t2)

In [9]:

    b64_t2

Out[9]:

    b'/////8gAAAAUAAAAAAAAAAwAFgAGAAUACAAMAAwAAAAAAwQAGAAAADAAAAAAAAAAAAAKABgADAAEAAgACgAAAGwAAAAQAAAAAgAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAADAAAAAAAAAAgAAAAAAAAAA0AAAAAAAAAAAAAAAIAAAACAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAoAAAAAAAAAMgAAAAAAAAAAAAAABQAAAA0AAAAAAAAAcGFkZHltYXJnYXJldAAAAA=='

In [10]:

    b64_t3 = '/////8gAAAAUAAAAAAAAAAwAFgAGAAUACAAMAAwAAAAAAwQAGAAAADAAAAAAAAAAAAAKABgADAAEAAgACgAAAGwAAAAQAAAAAgAAAAAAAAAAAAAABQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAABAAAAAAAAAADAAAAAAAAAAgAAAAAAAAAA0AAAAAAAAAAAAAAAIAAAACAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAoAAAAAAAAAMgAAAAAAAAAAAAAABQAAAA0AAAAAAAAAcGFkZHltYXJnYXJldAAAAA=='

In [11]:

    Base64Widget(df_base64=b64_t3)

Out[11]:
In [12]:

    len(b64_t2)

Out[12]:

    344

In [13]:

    pabuffer.size

Out[13]:

    256

In [14]:

    BytesWidget(df_arrow_bytes=pabuffer.to_pybytes())

Out[14]:
In [15]:

    BytesWidget(df_arrow_bytes=pabuffer.to_pybytes())

Out[15]:
In [ ]: