DataFrame 按列分组groupby

import pandas as pd

# 按列分组
data = {'A': ["aa", "bb", "cc", "bb"],
        'B': [5, 6, 10, 7],
        'C': [0, 10, 3, 12]}

df = pd.DataFrame(data)
print(df)
print(df.groupby('A', as_index=False).sum('bb'))

 

posted @ 2023-08-08 14:57  OTAKU_nicole  阅读(42)  评论(0编辑  收藏  举报