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] DataFrame swapaxes #9628

Closed
beckernick opened this issue Nov 8, 2021 · 1 comment
Closed

[FEA] DataFrame swapaxes #9628

beckernick opened this issue Nov 8, 2021 · 1 comment
Labels
feature request New feature or request good first issue Good for newcomers Python Affects Python cuDF API.

Comments

@beckernick
Copy link
Member

For pandas API compatibility, we can implement DataFrame.swapaxes. This appears to either return a transpose (swapping index and column axes) or the original frame. In both cases, the data is copied by default (but can be parameterized to return a view / the original frame instead).

Series.swapaxes is likely going to be deprecated in the future based on pandas-dev/pandas#18262 and the method itself is generally no longer useful since pandas removed Panels. There may be some numpy compatibility reasons it still exists, based on pandas-dev/pandas#26654 . If we eventually run into similar needs with CuPy, we can cross that bridge when we come to it.

import pandas as pddf = pd.DataFrame({
    "a": [0,1,None,3],
    "b": [3,9,20,1]
})
​
print(df)
print(df.swapaxes(0,0, copy=False))
print(df.swapaxes("index", "columns"))
print(df.swapaxes(1,0))
print(df.swapaxes(0,1))
     a   b
0  0.0   3
1  1.0   9
2  NaN  20
3  3.0   1
     a   b
0  0.0   3
1  1.0   9
2  NaN  20
3  3.0   1
     0    1     2    3
a  0.0  1.0   NaN  3.0
b  3.0  9.0  20.0  1.0
     0    1     2    3
a  0.0  1.0   NaN  3.0
b  3.0  9.0  20.0  1.0
     0    1     2    3
a  0.0  1.0   NaN  3.0
b  3.0  9.0  20.0  1.0
@beckernick beckernick added feature request New feature or request good first issue Good for newcomers Python Affects Python cuDF API. labels Nov 8, 2021
@vyasr
Copy link
Contributor

vyasr commented May 13, 2024

DataFrame.swapaxes was deprecated in pandas 2.1 (this issue) so it's not worth our time to implement it now.

@vyasr vyasr closed this as completed May 13, 2024
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

No branches or pull requests

2 participants