@@ -153,70 +153,14 @@ the correct dense result.
153
153
np.abs(arr)
154
154
np.abs(arr).to_dense()
155
155
156
- .. _sparse.migration :
157
-
158
- Migrating
159
- ---------
160
-
161
- .. note ::
162
-
163
- ``SparseSeries `` and ``SparseDataFrame `` were removed in pandas 1.0.0. This migration
164
- guide is present to aid in migrating from previous versions.
165
-
166
- In older versions of pandas, the ``SparseSeries `` and ``SparseDataFrame `` classes (documented below)
167
- were the preferred way to work with sparse data. With the advent of extension arrays, these subclasses
168
- are no longer needed. Their purpose is better served by using a regular Series or DataFrame with
169
- sparse values instead.
170
-
171
- .. note ::
172
-
173
- There's no performance or memory penalty to using a Series or DataFrame with sparse values,
174
- rather than a SparseSeries or SparseDataFrame.
175
-
176
- This section provides some guidance on migrating your code to the new style. As a reminder,
177
- you can use the Python warnings module to control warnings. But we recommend modifying
178
- your code, rather than ignoring the warning.
179
-
180
- **Construction **
181
-
182
- From an array-like, use the regular :class: `Series ` or
183
- :class: `DataFrame ` constructors with :class: `arrays.SparseArray ` values.
184
-
185
- .. code-block :: python
186
-
187
- # Previous way
188
- >> > pd.SparseDataFrame({" A" : [0 , 1 ]})
189
-
190
- .. ipython :: python
191
-
192
- # New way
193
- pd.DataFrame({" A" : pd.arrays.SparseArray([0 , 1 ])})
194
-
195
- From a SciPy sparse matrix, use :meth: `DataFrame.sparse.from_spmatrix `,
196
-
197
- .. code-block :: python
198
-
199
- # Previous way
200
- >> > from scipy import sparse
201
- >> > mat = sparse.eye(3 )
202
- >> > df = pd.SparseDataFrame(mat, columns = [' A' , ' B' , ' C' ])
203
-
204
- .. ipython :: python
205
-
206
- # New way
207
- from scipy import sparse
208
- mat = sparse.eye(3 )
209
- df = pd.DataFrame.sparse.from_spmatrix(mat, columns = [' A' , ' B' , ' C' ])
210
- df.dtypes
211
156
212
157
**Conversion **
213
158
214
- From sparse to dense, use the ``.sparse `` accessors
159
+ To convert data from sparse to dense, use the ``.sparse `` accessors
215
160
216
161
.. ipython :: python
217
162
218
- df.sparse.to_dense()
219
- df.sparse.to_coo()
163
+ sdf.sparse.to_dense()
220
164
221
165
From dense to sparse, use :meth: `DataFrame.astype ` with a :class: `SparseDtype `.
222
166
@@ -226,40 +170,6 @@ From dense to sparse, use :meth:`DataFrame.astype` with a :class:`SparseDtype`.
226
170
dtype = pd.SparseDtype(int , fill_value = 0 )
227
171
dense.astype(dtype)
228
172
229
- **Sparse Properties **
230
-
231
- Sparse-specific properties, like ``density ``, are available on the ``.sparse `` accessor.
232
-
233
- .. ipython :: python
234
-
235
- df.sparse.density
236
-
237
- **General differences **
238
-
239
- In a ``SparseDataFrame ``, *all * columns were sparse. A :class: `DataFrame ` can have a mixture of
240
- sparse and dense columns. As a consequence, assigning new columns to a :class: `DataFrame ` with sparse
241
- values will not automatically convert the input to be sparse.
242
-
243
- .. code-block :: python
244
-
245
- # Previous Way
246
- >> > df = pd.SparseDataFrame({" A" : [0 , 1 ]})
247
- >> > df[' B' ] = [0 , 0 ] # implicitly becomes Sparse
248
- >> > df[' B' ].dtype
249
- Sparse[int64, nan]
250
-
251
- Instead, you'll need to ensure that the values being assigned are sparse
252
-
253
- .. ipython :: python
254
-
255
- df = pd.DataFrame({" A" : pd.arrays.SparseArray([0 , 1 ])})
256
- df[' B' ] = [0 , 0 ] # remains dense
257
- df[' B' ].dtype
258
- df[' B' ] = pd.arrays.SparseArray([0 , 0 ])
259
- df[' B' ].dtype
260
-
261
- The ``SparseDataFrame.default_kind `` and ``SparseDataFrame.default_fill_value `` attributes
262
- have no replacement.
263
173
264
174
.. _sparse.scipysparse :
265
175
0 commit comments