-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: update the pandas.DataFrame.to_sparse docstring #20193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1570,16 +1570,44 @@ def from_csv(cls, path, header=0, sep=',', index_col=0, parse_dates=True, | |
|
||
def to_sparse(self, fill_value=None, kind='block'): | ||
""" | ||
Convert to SparseDataFrame | ||
Convert to SparseDataFrame. | ||
|
||
Implement the sparse version of the DataFrame meaning that any data | ||
matching a specific value it's omitted in the representation. | ||
The sparse DataFrame allows for a more efficient storage. | ||
|
||
Parameters | ||
---------- | ||
fill_value : float, default NaN | ||
The specific value that should be omitted in the representation. | ||
kind : {'block', 'integer'} | ||
The kind of the SparseIndex tracking where data is not equal to | ||
the fill value: | ||
|
||
- 'block' tracks only the locations and sizes of blocks of data; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if the semi-colon at the end is intentional. If you find another docstring with a list, I'd use the same convention. |
||
- 'integer' keeps an array with all the locations of the data. | ||
|
||
The kind 'block' is recommended since it's more memory efficient. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd say the same, but in a way that doesn't sound like 'block' is always better. Something like "In most cases, the default 'block' is preferred for being more memory efficient.". Not a big difference, but I'd prefer to avoid giving the idea that 'integer' is never the best option, which is not true. |
||
|
||
Returns | ||
------- | ||
y : SparseDataFrame | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can get rid of the |
||
|
||
See Also | ||
-------- | ||
DataFrame.to_dense : | ||
converts the DataFrame back to the its dense form | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you capitalize the first letter and add a period at the end? I think the description should start in the same line as |
||
|
||
Examples | ||
-------- | ||
|
||
Compressing on the zero value. | ||
|
||
>>> df = pd.DataFrame(np.random.randn(1000, 4)) | ||
>>> df.iloc[:995] = 0. | ||
>>> sdf = df.to_sparse(fill_value=0.) | ||
>>> sdf.density | ||
0.005 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice example. It's just an opinion, feel free to leave it like this, if you think that being somehow more realistic is better, but I'd have something like: |
||
""" | ||
from pandas.core.sparse.frame import SparseDataFrame | ||
return SparseDataFrame(self._series, index=self.index, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The default is missing.