df.sum()で数値列だけを対象にしたいとき2022/12/14 / 1 min readView more blogs with the tag pandas, View more blogs with the tag pythonTable of Contents#はじめに#方法はじめに df.sum()で数値列だけを対象にしたいときの例です。 方法 引数 numeric_only をセットするだけ import pandas as pd df = pd.DataFrame({ 'col1': ['a', 'b', 'c'], 'col2': [1, 2, 3], 'col3': [1, 2, 'a']}) df.sum(numeric_only=True) # 出力結果# col2 6# dtype: int64関連記事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