46 lines
856 B
Python
46 lines
856 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
|
|
|
|
|
|
|
|
from pandas import HDFStore
|
|
|
|
|
|
def to_hdf_binary(df):
|
|
with HDFStore(
|
|
"wontbewritten.h5",
|
|
mode="a",
|
|
driver="H5FD_CORE",
|
|
driver_core_backing_store=0
|
|
) as out:
|
|
out["/data"] = df
|
|
res = out._handle.get_file_image()
|
|
return res
|
|
|
|
|
|
|