Skip to content

clip dataframe column-wise #15390

Closed
@cnsgsz

Description

@cnsgsz

I have

In [67]: a
Out[67]:

   0  1  2
0  1  2  3
1  4  5  6

when I run

In [69]: a.clip(lower=[1.5,2.5,3.5],axis=1)

I got

----> 1 a.clip(lower=[1.5,2.5,3.5],axis=1)

/home/.../anaconda3/lib/python3.5/site-packages/pandas/core/generic.py in clip(self, lower, upper, axis, *args, **kwargs)
   3668         result = self
   3669         if lower is not None:
-> 3670             result = result.clip_lower(lower, axis)
   3671         if upper is not None:
   3672             result = result.clip_upper(upper, axis)

/home/.../anaconda3/lib/python3.5/site-packages/pandas/core/generic.py in clip_lower(self, threshold, axis)
   3720
   3721         subset = self.ge(threshold, axis=axis) | isnull(self)
-> 3722         return self.where(subset, threshold, axis=axis)
   3723
   3724     def groupby(self, by=None, axis=0, level=None, as_index=True, sort=True,

/home/.../anaconda3/lib/python3.5/site-packages/pandas/core/generic.py in where(self, cond, other, inplace, axis, level, try\
_cast, raise_on_error)
   4458
   4459                 else:
-> 4460                     raise ValueError('other must be the same shape as self '                                           
   4461                                      'when an ndarray')
   4462

ValueError: other must be the same shape as self when an ndarray

Is that expected?
I was expecting to get something like:

Out[72]:

     0    1    2
0  1.5  2.5  3.5
1  4.0  5.0  6.0

# Paste the output here pd.show_versions() here In [73]: pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.5.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.4.0-59-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8

pandas: 0.18.1
nose: 1.3.7
pip: 8.1.2
setuptools: 27.2.0
Cython: 0.24.1
numpy: 1.11.1
scipy: 0.18.1
statsmodels: 0.6.1
xarray: None
IPython: 5.1.0
sphinx: 1.4.6
patsy: 0.4.1
dateutil: 2.5.3
pytz: 2016.6.1
blosc: None
bottleneck: 1.1.0
tables: 3.2.3.1
numexpr: 2.6.1
matplotlib: 1.5.3
openpyxl: 2.3.2
xlrd: 1.0.0
xlwt: 1.1.2
xlsxwriter: 0.9.3
lxml: 3.6.4
bs4: 4.5.1
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.13
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.42.0
pandas_datareader: None

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions