def _sparse_series_to_coo(ss, row_levels=(0,), column_levels=(1,), sort_labels=False):
 import scipy.sparse
 if (ss.index.nlevels < 2):
  raise ValueError('to_coo requires MultiIndex with nlevels > 2')
 if (not ss.index.is_unique):
  raise ValueError('Duplicate index entries are not allowed in to_coo transformation.')
 row_levels = [ss.index._get_level_number(x) for x in row_levels]
 column_levels = [ss.index._get_level_number(x) for x in column_levels]
 (v, i, j, rows, columns) = _to_ijv(ss, row_levels=row_levels, column_levels=column_levels, sort_labels=sort_labels)
 sparse_matrix = scipy.sparse.coo_matrix((v, (i, j)), shape=(len(rows), len(columns)))
 return (sparse_matrix, rows, columns)

def _sparse_series_to_coo ( ss , row_levels = ( 0 , ) , column_levels = ( 1 , ) , sort_labels = False ) : import scipy . sparse if ( ss . index . nlevels < 2 ) : raise ValueError ( 'to_coo requires MultiIndex with nlevels > 2' ) if ( not ss . index . is_unique ) : raise ValueError ( 'Duplicate index entries are not allowed in to_coo transformation.' ) row_levels = [ ss . index . _get_level_number ( x ) for x in row_levels ] column_levels = [ ss . index . _get_level_number ( x ) for x in column_levels ] ( v , i , j , rows , columns ) = _to_ijv ( ss , row_levels = row_levels , column_levels = column_levels , sort_labels = sort_labels ) sparse_matrix = scipy . sparse . coo_matrix ( ( v , ( i , j ) ) , shape = ( len ( rows ) , len ( columns ) ) ) return ( sparse_matrix , rows , columns )
convert a sparseseries to a scipy .