呼啦一阵风
是pandas的可以做到:import pandas as pd# Create dataframe (or import it)df = pd.DataFrame({"id": [1, 1, 1, 2, 2, 3, 1, 4], "letter" : ["A", "A", "B", "D", "A", "C", "B", "B"]})print(df)结果: id letter0 1 A1 1 A2 1 B3 2 D4 2 A5 3 C6 1 B7 4 B然后:df.groupby("id").sum()print(df)结果:id letter1 AABB2 DA3 C4 B