36 lines
726 B
Python
36 lines
726 B
Python
import pandas as pd
|
|
|
|
|
|
class DateFrameHolder:
|
|
|
|
def __init__(self, df=None):
|
|
self.df = df or pd.DataFrame()
|
|
# self.df = pd.DataFrame.from_records([dict(a=1, b=2, c=3)] * 4) #TODO: remove
|
|
|
|
def append(self, data):
|
|
data = pd.DataFrame.from_records([data])
|
|
self.df = pd.concat([self.df, data], ignore_index=True)
|
|
|
|
def clear(self):
|
|
self.df = pd.DataFrame()
|
|
|
|
|
|
|
|
from io import BytesIO
|
|
|
|
|
|
def to_excel_binary(df, **kwargs):
|
|
with BytesIO() as out:
|
|
df.to_excel(out, **kwargs)
|
|
res = out.getvalue()
|
|
return res
|
|
|
|
def to_hdf_binary(df, key="df", **kwargs):
|
|
with BytesIO() as out:
|
|
df.to_hdf(out, key, **kwargs)
|
|
res = out.getvalue()
|
|
return res
|
|
|
|
|
|
|