Skip to content
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

[FEA] Add_suffix and add_prefix for DataFrames and Series #9590

Closed
beckernick opened this issue Nov 3, 2021 · 0 comments · Fixed by #9846
Closed

[FEA] Add_suffix and add_prefix for DataFrames and Series #9590

beckernick opened this issue Nov 3, 2021 · 0 comments · Fixed by #9846
Assignees
Labels
feature request New feature or request good first issue Good for newcomers Python Affects Python cuDF API.

Comments

@beckernick
Copy link
Member

Pandas provides add_suffix and add_prefix methods on DataFrames and Series. add_suffix. For API compatibility, it would be useful to implement them.

"For Series, the row labels are prefixed (suffixed). For DataFrame, the column labels are prefixed (suffixed)." [0].

If the labels are numeric, they are coerced to strings before concatenation.

[0] https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.add_prefix.html

import pandas as pddf = pd.DataFrame({'A': [1, 2, 3, 4], 'B': [3, 4, 5, 6]})
​
print(df)
print(df.add_suffix("_hello"))
print(df["A"])
print(df["A"].add_suffix("_hello"))
   A  B
0  1  3
1  2  4
2  3  5
3  4  6
   A_hello  B_hello
0        1        3
1        2        4
2        3        5
3        4        6
0    1
1    2
2    3
3    4
Name: A, dtype: int64
0_hello    1
1_hello    2
2_hello    3
3_hello    4
Name: A, dtype: int64
@beckernick beckernick added feature request New feature or request good first issue Good for newcomers Python Affects Python cuDF API. labels Nov 3, 2021
@mayankanand007 mayankanand007 self-assigned this Dec 3, 2021
@rapids-bot rapids-bot bot closed this as completed in #9846 Dec 8, 2021
rapids-bot bot pushed a commit that referenced this issue Dec 8, 2021
This PR fixes #9590, by adding `add_suffix` and `add_prefix` for `cudf.DataFrame` and `cudf.Series`.

To make things concise, we unify the docstrings of these methods in both `Series` and `DataFrame` by defining them within `IndexedFrame` (with a unified docstring and raising `NotImplementedError`, asking the user to refer to the implementations in `Series` or `DataFrame`)

Its preferred to raise `NotImplementedError` so that if someone later creates another class by inheriting from `IndexedFrame`, it clarifies that they must reimplement `add_suffix` and `add_prefix`

Authors:
  - Mayank Anand (https://github.com/mayankanand007)

Approvers:
  - Charles Blackmon-Luca (https://github.com/charlesbluca)
  - GALI PREM SAGAR (https://github.com/galipremsagar)
  - https://github.com/brandon-b-miller

URL: #9846
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request good first issue Good for newcomers Python Affects Python cuDF API.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants