我有此代码:
pd.crosstab(cars.Origin,cars.Type)
我得到的输出是:
我正在尝试使用标准化,但这给我一个错误。 是我做错了还是安装有问题?
pd.crosstab(cars.Origin,cars.Type, normalize=True)
我收到以下错误。请指教
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
/opt/Anaconda/2018.12/lib/python3.7/site-packages/pandas/core/internals.py in eval(self, func, other, errors, try_cast, mgr)
/opt/Anaconda/2018.12/lib/python3.7/site-packages/pandas/core/internals.py in get_result(other)
/opt/Anaconda/2018.12/lib/python3.7/site-packages/pandas/core/ops.py in na_op(x, y)
/opt/Anaconda/2018.12/lib/python3.7/site-packages/pandas/core/computation/expressions.py in <module>
17 from pandas.core.computation.check import _NUMEXPR_INSTALLED
---> 18 from pandas.core.ops import roperator
19
ImportError: cannot import name 'roperator' from 'pandas.core.ops' (/opt/Anaconda/2018.12/lib/python3.7/site-packages/pandas/core/ops.py)
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-44-d5b72ea5be76> in <module>
----> 1 pd.crosstab(cars.Origin,cars.Type, normalize=True)
/opt/Anaconda/2018.12/lib/python3.7/site-packages/pandas/core/reshape/pivot.py in crosstab(index, columns, values, rownames, colnames, aggfunc, margins, margins_name, dropna, normalize)
495 aggregation function are passed.
496
--> 497 Parameters
498 ----------
499 index : array-like, Series, or list of arrays/Series
/opt/Anaconda/2018.12/lib/python3.7/site-packages/pandas/core/reshape/pivot.py in _normalize(table, normalize, margins, margins_name)
526
527 Returns
--> 528 -------
529 DataFrame
530 Cross tabulation of the data.
/opt/Anaconda/2018.12/lib/python3.7/site-packages/pandas/core/reshape/pivot.py in <lambda>(x)
514 margins_name : str, default 'All'
515 Name of the row/column that will contain the totals
--> 516 when margins is True.
517 dropna : bool, default True
518 Do not include columns whose entries are all NaN.
/opt/Anaconda/2018.12/lib/python3.7/site-packages/pandas/core/ops.py in f(self, other, axis, level, fill_value)
/opt/Anaconda/2018.12/lib/python3.7/site-packages/pandas/core/frame.py in _combine_const(self, other, func, errors, try_cast)
4777 values = index._values
4778 if not isinstance(index, (PeriodIndex, DatetimeIndex)):
-> 4779 if values.dtype == np.object_:
4780 values = lib.maybe_convert_objects(values)
4781
/opt/Anaconda/2018.12/lib/python3.7/site-packages/pandas/core/internals.py in eval(self, **kwargs)
/opt/Anaconda/2018.12/lib/python3.7/site-packages/pandas/core/internals.py in apply(self, f, axes, filter, do_integrity_check, consolidate, **kwargs)
/opt/Anaconda/2018.12/lib/python3.7/site-packages/pandas/core/internals.py in eval(self, func, other, errors, try_cast, mgr)
/opt/Anaconda/2018.12/lib/python3.7/site-packages/pandas/core/internals.py in handle_error()
TypeError: Could not operate 428 with block values cannot import name 'roperator' from 'pandas.core.ops' (/opt/Anaconda/2018.12/lib/python3.7/site-packages/pandas/core/ops.py)