I noticed Pandas now has support for Sparse Matrices and Arrays. Currently, I create DataFrame()s like this:
DataFrame()
return DataFrame(matrix.toarray(),
As of pandas v 0.20.0 you can use the SparseDataFrame constructor.
SparseDataFrame
An example from the pandas docs:
import numpy as np import pandas as pd from scipy.sparse import csr_matrix arr = np.random.random(size=(1000, 5)) arr[arr < .9] = 0 sp_arr = csr_matrix(arr) sdf = pd.SparseDataFrame(sp_arr)