df.sum()で数値列だけを対象にしたいとき 2022年12月14日 / 1 min read View more blogs with the tag pandas , View more blogs with the tag python Table 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