我正在尝试使用名为bidi的Python包.在这个包中的模块(algorithm.py)中,有一些行给出了错误,尽管它是包的一部分.
以下是这些行:
# utf-8 ? we need unicode
if isinstance(unicode_or_str, unicode):
text = unicode_or_str
decoded = False
else:
text = unicode_or_str.decode(encoding)
decoded = True
Run Code Online (Sandbox Code Playgroud)
这是错误信息:
Traceback (most recent call last):
File "<pyshell#25>", line 1, in <module>
bidi_text = get_display(reshaped_text)
File "C:\Python33\lib\site-packages\python_bidi-0.3.4-py3.3.egg\bidi\algorithm.py", line 602, in get_display
if isinstance(unicode_or_str, unicode):
NameError: global name 'unicode' is not defined
Run Code Online (Sandbox Code Playgroud)
我应该如何重写这部分代码,以便它在Python3中工作?如果有人使用Python 3的bidi包,请告诉我他们是否发现了类似的问题.我感谢您的帮助.
编辑: .mean() 函数工作得恰到好处:
renda['age'].mean()
Run Code Online (Sandbox Code Playgroud)
我仍然不确定为什么会出现下面和答案中提到的错误,但这有助于作为捷径。
我有一个 DataFrame renda,其中有一列age,我需要得到年龄的平均值。我写
t_age = renda['age'].sum()
renda.index = renda.index.map(int) #intended solution
last_id = renda.iloc(-1)
print(t_age/last_id)
Run Code Online (Sandbox Code Playgroud)
试图从这里调整答案。但它仍然不起作用,并引发了此错误:
TypeError: unsupported operand type(s) for /: 'int' and '_iLocIndexer'
Run Code Online (Sandbox Code Playgroud)
我能做些什么来解决这个问题?谢谢!
@斯科特波士顿:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/opt/conda/lib/python3.6/site-packages/pandas/core/ops.py in na_op(x, y)
657 result = expressions.evaluate(op, str_rep, x, y,
--> 658 raise_on_error=True, **eval_kwargs)
659 except TypeError:
/opt/conda/lib/python3.6/site-packages/pandas/core/computation/expressions.py in evaluate(op, op_str, a, b, raise_on_error, use_numexpr, **eval_kwargs)
210 return _evaluate(op, op_str, a, b, raise_on_error=raise_on_error,
--> 211 …Run Code Online (Sandbox Code Playgroud)