parsing - Way to parse Python pandas DataFrame to Matrix Market (MM) Format? -


is there built-in way write python pandas.dataframe object (stored 2x2 numpy.ndarray internally) matrix market (mm) format? have use cases both sparse , dense matrices.

when "built-in" here mean built pandas package. if not pandas, there can take dataframe or 2x2 numpy.ndarray , this?

i'm pretty sure there's nothing built in pandas, if have full stack installed can use scipy:

>>> import scipy.io, scipy.sparse >>> df = pd.dataframe({"a": [1,2], "b": [3,0]}) >>> scipy.io.mmwrite("mmout", df) >>> !cat mmout.mtx %%matrixmarket matrix array integer general % 2 2 1 2 3 0 

it'll work sparse case:

>>> scipy.io.mmwrite("mmout", scipy.sparse.csr_matrix(df)) >>> !cat mmout.mtx %%matrixmarket matrix coordinate integer general % 2 2 3 1 1 1 1 2 3 2 1 2 

although you'd have construct copy.


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -