Skip to content
Advertisement

how to sum values in column based on names reported in another column and report which name does not match the expected target? [closed]

how to sum calc values for each name and report if = 100.0000?

df example

output:

name “a” is not 100

output df

Advertisement

Answer

df[['name', 'calc']].groupby('name').sum()

should give you the sums for each name, should return the output you were looking for

to report which names arent equal to 100, try

df1=(df[['name', 'calc']].groupby('name').sum()!=100)

for name in df1.index[df1['calc']==True].to_list():
    print(f'calc of name:{name} does not match target')
Advertisement