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

df.squeeze() doesn't support axis parameter #15339

Closed
kernc opened this issue Feb 8, 2017 · 2 comments
Closed

df.squeeze() doesn't support axis parameter #15339

kernc opened this issue Feb 8, 2017 · 2 comments
Labels
API Design Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@kernc
Copy link
Contributor

kernc commented Feb 8, 2017

Code Sample, a copy-pastable example if possible

>>> df = pd.DataFrame([1], columns=['A'])

>>> df 
   A
0  1

>>> df.squeeze()
1

>>> type(df.squeeze())
numpy.int64

>>> df.squeeze(axis=1)  # Only want to squeeze a single dimension, i.e. into a series
...
ValueError: the 'axis' parameter is not supported in the pandas implementation of squeeze()

Problem description

np.squeeze supports axis parameter and this comment in the source implies it should eventually be implemented.

Expected Output

>>> df.squeeze(axis=1)  # Squeeze a single dimension, i.e. into a series
0    1
Name: A, dtype: int64

>>> df.squeeze(axis=0)
A    1
Name: 0, dtype: int64

Output of pd.show_versions()

pandas: 0.19.0+416.ge1390cd

@jreback
Copy link
Contributor

jreback commented Feb 8, 2017

@kernc how is this actually useful though? numpy needs this because of n-dim shrinking to a lower dim. pandas generally has 2-dim max so this is not so important.

@jreback jreback added API Design Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Feb 8, 2017
@kernc
Copy link
Contributor Author

kernc commented Feb 8, 2017

Indeed, as the example shows, it is only useful to squeeze a 1×1 frame into a series instead of a scalar, or to keep 1×N frame a frame. 😃

@jreback jreback added this to the 0.20.0 milestone Feb 8, 2017
@jreback jreback closed this as completed in 87c2c2a Feb 8, 2017
AnkurDedania pushed a commit to AnkurDedania/pandas that referenced this issue Mar 21, 2017
closes pandas-dev#15339

Author: Kernc <kerncece@gmail.com>

Closes pandas-dev#15335 from kernc/squeeze_axis_param and squashes the following commits:

44d3c54 [Kernc] fixup! ENH: .squeeze accepts axis parameter
cc018c9 [Kernc] ENH: .squeeze accepts axis parameter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

2 participants