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

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

Comments

Projects
None yet
2 participants
Contributor

kernc commented Feb 8, 2017 edited

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

kernc referenced this issue Feb 8, 2017

Closed

ENH: .squeeze accepts axis parameter #15335

4 of 4 tasks complete
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.

Contributor

kernc commented Feb 8, 2017 edited

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 added this to the 0.20.0 milestone Feb 8, 2017

jreback closed this in 87c2c2a Feb 8, 2017

@AnkurDedania AnkurDedania added a commit to AnkurDedania/pandas that referenced this issue Mar 21, 2017

@kernc @AnkurDedania kernc + AnkurDedania ENH: .squeeze has gained the axis parameter
closes #15339

Author: Kernc <kerncece@gmail.com>

Closes #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
5d7a777
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment