Python

Python

pandasのquery()で複数条件を指定して条件抽出する方法

pandasの条件抽出ではdf.loc()を使っているサンプルが多い気がするが、読んでてややこしい それに比べて、df.query()を使うと可読性が高い 後で見返したときでも分かりやすいので保守しやすくなるというメリットがある 乱数のデー...
Python

Pythonのif文でRemove redundant parentheses

Pythonでif文を書いていた時のこと if (a == b): とすると Remove redundant parentheses 直訳すると「冗長な括弧を取れ」ということになり、if分は()が不要だとわかる if a == b: これ...
Python

COCO APIのインストールでerror: no such file or directory: ‘pycocotools/_mask.c’

Tensorflow Object Detection APIを導入するにあたり、COCO API installationが必要 git clone cd cocoapi/PythonAPI make が、エラー発生。 clang: er...
Python

裏で動いているJupyter Notebookのサーバーを落とすコマンド

PyCharmでJupyter Notebookを動かしていたら急にフリーズして強制終了する羽目になった。 裏でJupyter Notebookのサーバーが動いているので、ブラウザからアクセスするとToken authentication ...
Python

Jupyter Notebook でエラー ‘prompt-toolkit<2.0.0,>=1.0.15′ distribution was not found and is required by ipython

Jupyter Notebook を実行してみるとエラー発生 resources.DistributionNotFound: The 'prompt-toolkit<2.0.0,>=1.0.15' distribution was not ...
Python

Pythonで実行時のwarningが出ないようにする

warningが表示されても、改善策を教えてくれるわけでもなく、エラー解決に役立たないことが多い。 実行時の煩わしいwarningを非表示にする。 import warnings warnings.filterwarnings('ignor...
Python

複数の変数に値を代入しようとして ‘int’ object is not iterable が出る

複数の変数に同じ値を入れたくてこんなコードを書いた。 a, b = 0 実行すると怒られる TypeError: 'int' object is not iterable 正しくは a = b = 0 a, b = 0, 0 3個以上の変数...