-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
DOC: update the pandas.Index.is_categorical docstring #20167
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 2 commits
354795e
1755bee
5a972b4
e6e12c6
a4586f2
218737a
1461f4a
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 |
---|---|---|
|
@@ -1156,7 +1156,7 @@ def to_frame(self, index=True): | |
>>> idx = pd.Index(['Ant', 'Bear', 'Cow'], name='animal') | ||
>>> idx.to_frame() | ||
animal | ||
animal | ||
animal | ||
Ant Ant | ||
Bear Bear | ||
Cow Cow | ||
|
@@ -1471,6 +1471,41 @@ def is_object(self): | |
return is_object_dtype(self.dtype) | ||
|
||
def is_categorical(self): | ||
""" | ||
Check if the Index type is categorical. | ||
|
||
The given object must be a pandas DataFrame or pandas Series. | ||
|
||
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 agree! Thank you :) |
||
Returns | ||
------- | ||
boolean | ||
True if index is categorical. | ||
|
||
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. Thanks a lot for the See Also! |
||
Examples | ||
-------- | ||
>>> s = pd.Series(["Watermelon", "Orange", "Apple", | ||
... "Watermelon"]).astype('category') | ||
>>> df = pd.DataFrame({'Weight (grams)': [2000, 230, 160, 1300]}, | ||
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. don't create a DataFrame here just to use its index, just use the series above 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. Ok, Thank you! I have changed the examples. |
||
... index=s) | ||
>>> df | ||
Weight (grams) | ||
Watermelon 2000 | ||
Orange 230 | ||
Apple 160 | ||
Watermelon 1300 | ||
>>> df.index.is_categorical() | ||
True | ||
|
||
>>> s = pd.Series(["Peter", "Adam", "Elisabeth", "Margareth"]) | ||
>>> s | ||
0 Peter | ||
1 Adam | ||
2 Elisabeth | ||
3 Margareth | ||
dtype: object | ||
>>> s.index.is_categorical() | ||
False | ||
""" | ||
return self.inferred_type in ['categorical'] | ||
|
||
def is_interval(self): | ||
|
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.
this only applies to a Series or an Index, IOW it must be 1D
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.
Thanks @jreback ! I have changed the exended summary. Is it better now?