DataFrameのインデックスを列名に変更する2022/3/9 / 1 min readView more blogs with the tag python, View more blogs with the tag pandasTable of Contents#問題#解決方法問題 pandas で groupby すると、groupby で使った列がインデックスになってしまう。 解決方法 インデックスを列に戻す方法です。 df = df.groupby('列名').sum()df = df.rename_axis('列名').reset_index() # 複数列でgroupbyした場合はリストで渡すだけdf = df.groupby(['列名1', '列名2']).sum()df = df.rename_axis(['列名1', '列名2']).reset_index()関連記事2026/8/16pandas前処理まとめ|結合・エンコーディング・欠損の右詰め・単語頻度2026/8/9Google Colaboratory活用まとめ|Drive連携・GPU・MeCab・Selenium2023/7/20SQLAlchemy2.0以降を使ってread_sqlする方法2023/5/17indexメソッドを利用した複数条件でdfの行を削除する2023/4/26Pandasのテーブルをまとめて一つのエクセルに出力したいときこの記事を書いた人barorin公認会計士会計とITの二足のわらじで働く公認会計士です。Pythonを中心に、会計・監査の実務で実際に使っているコードや、Ubuntu・Raspberry Piの設定メモを書いています。Find me onGithubFedibirdTwitterBuyMeACoffeeRSS