Skip to content

DOC: Updated the docstring of pandas.Series.str.get #20630

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion pandas/core/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -1651,17 +1651,34 @@ def str_translate(arr, table, deletechars=None):

def str_get(arr, i):
"""
Extract element for each component.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is not very clear. May be "Extract element from the specified position" or "Extract element from the specified position in a list or string" if not too long.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay. How about, "Extract element for each component from the specified position." or "Extract the element from the specified position for all elements in Series."; something along those lines?


Extract element from lists, tuples, or strings in each element in the
Series/Index.

Parameters
----------
i : int
Integer index (location)
Integer index (location).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this not very clear. May be something like "Position of the element to extract"?


Returns
-------
items : Series/Index of objects

Examples
--------
>>> x = pd.Series(["String", (1, 2, 4), ["a", "b", "c"]])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard way is to name the Series s and not x.

>>> x
0 String
1 (1, 2, 4)
2 [a, b, c]
dtype: object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a numerical value, to show what happens.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since get is a method for strings, I didn't add a numerical value (using one returns 'NaN'). However, it can be added it if you say.


>>> x.str.get(1)
0 t
1 2
2 b
dtype: object
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be a example with a negative value too?

"""
f = lambda x: x[i] if len(x) > i >= -len(x) else np.nan
return _na_map(f, arr)
Expand Down