2
問題:カテゴリ列を持つデータフレームとの句はとValueErrorを生成どこ使用して:私はちょうど私が間違っているのかを把握することはできません寸法エラーどこパンダとカテゴリの列を持つ
の数が誤っています。
df=pd.read_csv("F:/python/projects/mail/Inbox_20160911-1646/rows.csv",header=0,sep=",",quotechar="'",quoting=1)
df.where(df > 100) # WORKS !!!!
for c in [x for x in df.columns[2:] if df[x].dtype == "object" ]:
cl="c"+c
df[cl]=df[c].astype("category")
df.where(df > 100) # ---> ValueError: Wrong number of dimensions
df.where(df > 100)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-278-7469c620cf83> in <module>()
----> 1 df.where(df > 100)
F:\python\anaconda3\lib\site-packages\pandas\core\ops.py in f(self, other)
1182 # straight boolean comparisions we want to allow all columns
1183 # (regardless of dtype to pass thru) See #4537 for discussion.
-> 1184 res = self._combine_const(other, func, raise_on_error=False)
1185 return res.fillna(True).astype(bool)
1186
F:\python\anaconda3\lib\site-packages\pandas\core\frame.py in _combine_const(self, other, func, raise_on_error)
3553
3554 new_data = self._data.eval(func=func, other=other,
-> 3555 raise_on_error=raise_on_error)
3556 return self._constructor(new_data)
3557
F:\python\anaconda3\lib\site-packages\pandas\core\internals.py in eval(self, **kwargs)
2909
2910 def eval(self, **kwargs):
-> 2911 return self.apply('eval', **kwargs)
2912
2913 def quantile(self, **kwargs):
F:\python\anaconda3\lib\site-packages\pandas\core\internals.py in apply(self, f, axes, filter, do_integrity_check, consolidate, raw, **kwargs)
2888
2889 kwargs['mgr'] = self
-> 2890 applied = getattr(b, f)(**kwargs)
2891 result_blocks = _extend_blocks(applied, result_blocks)
2892
F:\python\anaconda3\lib\site-packages\pandas\core\internals.py in eval(self, func, other, raise_on_error, try_cast, mgr)
1160 result = self._try_cast_result(result)
1161
-> 1162 return [self.make_block(result, fastpath=True,)]
1163
1164 def where(self, other, cond, align=True, raise_on_error=True,
F:\python\anaconda3\lib\site-packages\pandas\core\internals.py in make_block(self, values, placement, ndim, **kwargs)
179 ndim = self.ndim
180
--> 181 return make_block(values, placement=placement, ndim=ndim, **kwargs)
182
183 def make_block_same_class(self, values, placement=None, fastpath=True,
F:\python\anaconda3\lib\site-packages\pandas\core\internals.py in make_block(values, placement, klass, ndim, dtype, fastpath)
2516 placement=placement, dtype=dtype)
2517
-> 2518 return klass(values, ndim=ndim, fastpath=fastpath, placement=placement)
2519
2520 # TODO: flexible with index=None and/or items=None
F:\python\anaconda3\lib\site-packages\pandas\core\internals.py in __init__(self, values, ndim, fastpath, placement, **kwargs)
1661
1662 super(ObjectBlock, self).__init__(values, ndim=ndim, fastpath=fastpath,
-> 1663 placement=placement, **kwargs)
1664
1665 @property
F:\python\anaconda3\lib\site-packages\pandas\core\internals.py in __init__(self, values, placement, ndim, fastpath)
79 ndim = values.ndim
80 elif values.ndim != ndim:
---> 81 raise ValueError('Wrong number of dimensions')
82 self.ndim = ndim
83
とValueError:ここ寸法
ありがとう!これは岩です。 –
@JulianC、あなたは大歓迎です!あなたの質問に – MaxU
が答えたと思うなら、[accepting](http://meta.stackexchange.com/a/5235)の答えを考えてください! ...残念なことに緑色の豆は...これを行う方法も知らなかった:-) –