pandas Typeエラー
python pandas学習中の初心者です。
https://note.nkmk.me/python-pandas-where-mask/
こちらのサイトを参考にして print(df < 0)
を実行したところ、下記のエラーが表示されます。
回避方法をご教授お願いします。
DataFremeデータサンプル
>>> df
A B C D
0 -20 1 a -20
1 -10 2 b 2
2 0 3 b 3
3 10 4 a 10
4 20 5 c 5
エラーが出る部分
>>> print(df < 0)
Traceback (most recent call last):
File "<pyshell#71>", line 1, in <module>
print(df < 0)
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\ops\__init__.py", line 1579, in f
res = self._combine_const(other, func)
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\frame.py", line 5418, in _combine_const
return ops.dispatch_to_series(self, other, func)
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\ops\__init__.py", line 596, in dispatch_to_series
new_data = expressions.evaluate(column_op, str_rep, left, right)
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\computation\expressions.py", line 221, in evaluate
return _evaluate(op, op_str, a, b, **eval_kwargs)
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\computation\expressions.py", line 70, in _evaluate_standard
return op(a, b)
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\ops\__init__.py", line 570, in column_op
return {i: func(a.iloc[:, i], b) for i in range(len(a.columns))}
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\ops\__init__.py", line 570, in <dictcomp>
return {i: func(a.iloc[:, i], b) for i in range(len(a.columns))}
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\ops\__init__.py", line 1229, in wrapper
res = na_op(values, other)
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\ops\__init__.py", line 1091, in na_op
result = _comp_method_OBJECT_ARRAY(op, x, y)
File "C:\Users\XXXXX\AppData\Local\Programs\Python\Python37-32\lib\site-packages\pandas\core\ops\__init__.py", line 1069, in _comp_method_OBJECT_ARRAY
result = libops.scalar_compare(x, y, op)
File "pandas/_libs/ops.pyx", line 96, in pandas._libs.ops.scalar_compare
TypeError: '<' not supported between instances of 'str' and 'int'