Python

Python

statsmodelsの回帰分析で切片interceptを追加する方法

statsmodelで回帰分析を行った時のことimport statsmodels.api as smmodel = sm.OLS(Y, X)results = model.fit()print(results.summary())こんな感...
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:これでOK
Python

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

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

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

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

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

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

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

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