-
-
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 1 commit
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,40 @@ 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 | ||
---------- | ||
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. This should be the same length as "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", | ||
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. Space after "," 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. space after the commas |
||
... "Watermelon"]).astype('category') | ||
>>> df = pd.DataFrame({'Weight (grams)':[2000,230,160,1300]}, index=s) | ||
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. spcae after the colon. Space after commas. 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. Thank you for your comments ^^ !! We have already changed it. 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. Space after "," 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, we appreciate your comments! We have already changed it :) |
||
>>> df | ||
Weight (grams) | ||
Watermelon 2000 | ||
Orange 230 | ||
Apple 160 | ||
Watermelon 1300 | ||
>>> df.index.is_categorical() | ||
True | ||
|
||
>>> df = pd.Series(["Peter","Adam","Elisabeth","Margareth"]) | ||
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. call the |
||
>>> df | ||
0 Peter | ||
1 Adam | ||
2 Elisabeth | ||
3 Margareth | ||
dtype: object | ||
>>> df.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.
dataframe -> DataFrame