I want to cast a DataFrame to sparse matrix using csr_matrix
from scipy library, but first I have to convert it to a SparseDataFrame. In previous versions of pandas I used pd.SparseDataFrame(df).to_coo()
for such purposes, but since pandas 1.0.0
this method is deprecated. Does anyone know how to perform such conversion using latest pandas api. I used this migration guide and tried various combination but still unable to achieve desired result.
Following the guide, when I do the following
csr_matrix(pd.DataFrame.sparse.from_spmatrix(df).to_coo())
I get this error
AttributeError: 'DataFrame' object has no attribute 'tocsc'
Can anyone help me how to solve this? Also I do find other posts, but couldn't helped me in my case link link link