module df.dataframe_io
¶
Short summary¶
module pandas_streaming.df.dataframe_io
Functions¶
function |
truncated documentation |
---|---|
Reads a dataframe from a zip file. It can be saved by |
|
Saves a Dataframe into a zip file. It can be read by |
Documentation¶
Saves and reads a dataframe into a zip file.
- pandas_streaming.df.dataframe_io.read_zip(zipfilename, zname=None, **kwargs)¶
Reads a dataframe from a zip file. It can be saved by
read_zip
.- Parameters:
zipfilename – a zipfile.ZipFile or a filename
zname – a filename in zipfile, if None, takes the first one
kwargs – parameters for
pandas.read_csv()
- Returns:
pandas.DataFrame()
or numpy.array
- pandas_streaming.df.dataframe_io.to_zip(df, zipfilename, zname='df.csv', **kwargs)¶
Saves a Dataframe into a zip file. It can be read by
to_zip
.- Parameters:
df – dataframe or numpy.array
zipfilename – a zipfile.ZipFile or a filename
zname – a filename in th zipfile
kwargs – parameters for pandas.to_csv or numpy.save
- Returns:
zipfilename
Saves and reads a dataframe in a zip file
This shows an example on how to save and read a pandas.dataframe directly into a zip file.
<<<
import pandas from pandas_streaming.df import to_zip, read_zip df = pandas.DataFrame([dict(a=1, b="e"), dict(b="f", a=5.7)]) name = "dfs.zip" to_zip(df, name, encoding="utf-8", index=False) df2 = read_zip(name, encoding="utf-8") print(df2)
>>>
a b 0 1.0 e 1 5.7 f
Saves and reads a numpy array in a zip file
This shows an example on how to save and read a numpy.ndarray directly into a zip file.
<<<
import numpy from pandas_streaming.df import to_zip, read_zip arr = numpy.array([[0.5, 1.5], [0.4, 1.6]]) name = "dfsa.zip" to_zip(arr, name, 'arr.npy') arr2 = read_zip(name, 'arr.npy') print(arr2)
>>>
[[0.5 1.5] [0.4 1.6]]