0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

VSCode + venv + pandas の DataFrame 出力を省略しないための設定(自分用メモ)

0
Last updated at Posted at 2025-12-11

VSCode の Jupyter Notebook (.ipynb) で pandas の DataFrame を表示する際、行数や列数が多いと ... と省略されてしまうことがあります。

プロジェクトごとの仮想環境(venv)に sitecustomize.py を配置することで、コード内で毎回設定を書くことなく、常に全件表示するように設定する方法の備忘録です。

使用環境

  • VS Code
  • Python (venv による仮想環境)
  • pandas

解決したい課題

  • pandas の DataFrame を常に省略せず(フルで)表示したい
  • *.ipynb 上で dfprint(df) を実行した際の省略をなくしたい

手順

1. venv の site-packages ディレクトリを確認する

プロジェクト内の venv 構造において、site-packages がどこにあるかを確認します。

ディレクトリ構造の例:

<project>/
└── .venv/
    ├── bin/
    └── lib/
        └── python3.x/  # ここのバージョンは環境により異なります
            └── site-packages/

パスの例:
<project>/.venv/lib/python3.10/site-packages/


2. sitecustomize.py を作成する

site-packages/ 直下に sitecustomize.py という名前でファイルを作成します。このファイルは Python 起動時に自動的に読み込まれます。

作成するファイル:
site-packages/sitecustomize.py

記述内容:

sitecustomize.py
import pandas as pd

# 表示行数の制限をなくす
pd.set_option("display.max_rows", None)
# 表示列数の制限をなくす
pd.set_option("display.max_columns", None)
# 表示幅の自動調整(0は自動)
pd.set_option("display.width", 0)
# Jupyter上でのリッチなテーブル表示を有効化
pd.set_option("display.html.table_schema", True)

作成後のディレクトリ構造:

<project>/
└── .venv/
    ├── bin/
    └── lib/
        └── python3.x/
            └── site-packages/
                ├── sitecustomize.py  <-- これを追加
                └── (その他のパッケージ群...)

3. 設定の反映

VS Code の Jupyter カーネルを再起動するか、ターミナルで venv をアクティブにして Python を再起動します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?