Categories
pandas python scipy sparse-matrix

Pandas sparse dataFrame to sparse matrix, without generating a dense matrix in memory

Is there a way to convert from a pandas.SparseDataFrame to scipy.sparse.csr_matrix, without generating a dense matrix in memory?

scipy.sparse.csr_matrix(df.values)

doesn’t work as it generates a dense matrix which is cast to the csr_matrix.

Thanks in advance!