-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Fixing EX01 - Added examples #53403
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
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 |
---|---|---|
|
@@ -1056,6 +1056,14 @@ def astype(self, dtype, copy: bool = True): | |
------- | ||
Index | ||
Index with values cast to specified dtype. | ||
|
||
Examples | ||
-------- | ||
>>> idx = pd.Index([1, 2, 3]) | ||
>>> idx | ||
Index([1, 2, 3], dtype='int64') | ||
>>> idx.astype('float') | ||
Index([1.0, 2.0, 3.0], dtype='float64') | ||
""" | ||
if dtype is not None: | ||
dtype = pandas_dtype(dtype) | ||
|
@@ -2939,6 +2947,12 @@ def fillna(self, value=None, downcast=None): | |
-------- | ||
DataFrame.fillna : Fill NaN values of a DataFrame. | ||
Series.fillna : Fill NaN Values of a Series. | ||
|
||
Examples | ||
-------- | ||
>>> idx = pd.Index([None, np.nan, 3]) | ||
>>> idx.fillna(0) | ||
Index([0.0, 0.0, 3.0], dtype='float64') | ||
""" | ||
if not is_scalar(value): | ||
raise TypeError(f"'value' must be a scalar, passed: {type(value).__name__}") | ||
|
@@ -2969,6 +2983,12 @@ def dropna(self, how: AnyAll = "any") -> Self: | |
Returns | ||
------- | ||
Index | ||
|
||
Examples | ||
-------- | ||
>>> idx = pd.Index([1, None, 3]) | ||
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. same here 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. Yes - thanks |
||
>>> idx.dropna() | ||
Index([1.0, 3.0], dtype='float64') | ||
""" | ||
if how not in ("any", "all"): | ||
raise ValueError(f"invalid how option: {how}") | ||
|
@@ -4535,6 +4555,13 @@ def join( | |
Returns | ||
------- | ||
join_index, (left_indexer, right_indexer) | ||
|
||
Examples | ||
-------- | ||
>>> idx1 = pd.Index([1, 2, 3]) | ||
>>> idx2 = pd.Index([4, 5, 6]) | ||
>>> idx1.join(idx2, how='outer') | ||
Index([1, 2, 3, 4, 5, 6], dtype='int64') | ||
""" | ||
other = ensure_index(other) | ||
|
||
|
@@ -5359,6 +5386,12 @@ def append(self, other: Index | Sequence[Index]) -> Index: | |
Returns | ||
------- | ||
Index | ||
|
||
Examples | ||
-------- | ||
>>> idx = pd.Index([1, 2, 3]) | ||
>>> idx.append(pd.Index([4])) | ||
Index([1, 2, 3, 4], dtype='int64') | ||
""" | ||
to_concat = [self] | ||
|
||
|
@@ -6295,6 +6328,22 @@ def map(self, mapper, na_action: Literal["ignore"] | None = None): | |
The output of the mapping function applied to the index. | ||
If the function returns a tuple with more than one element | ||
a MultiIndex will be returned. | ||
|
||
Examples | ||
-------- | ||
>>> idx = pd.Index([1, 2, 3]) | ||
>>> idx.map({1: 'a', 2: 'b', 3: 'c'}) | ||
Index(['a', 'b', 'c'], dtype='object') | ||
|
||
Using `map` with a function: | ||
|
||
>>> idx = pd.Index([1, 2, 3]) | ||
>>> idx.map('I am a {}'.format) | ||
Index(['I am a 1', 'I am a 2', 'I am a 3'], dtype='object') | ||
Comment on lines
+6340
to
+6342
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 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. There was something similar already in the docs. I stole it. :-) |
||
|
||
>>> idx = pd.Index(['a', 'b', 'c']) | ||
>>> idx.map(lambda x: x.upper()) | ||
Index(['A', 'B', 'C'], dtype='object') | ||
""" | ||
from pandas.core.indexes.multi import MultiIndex | ||
|
||
|
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.
although you're constructing with
None
andnp.nan
, they both get converted tonp.nan
To reduce the chance for confusion, shall we just construct with
np.nan
directly?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.
Sure