All row sum with pandas except one All row sum with pandas except one postgresql postgresql

All row sum with pandas except one


Use drop + sum:

df['sum'] = df.drop('gid', axis=1).sum(axis=1)print (df)   gid  col2  col1  col3    sum0    6    15  45.0    77  137.01    1    15  45.0    57  117.02    2    14   0.2    42   56.23    3    12   6.0    37   55.04    4     9  85.0    27  121.05    5     5   1.0    15   21.0

If gid is always first column, select by iloc all columns without first and then sum them:

df['sum'] = df.iloc[:, 1:].sum(axis=1)print (df)   gid  col2  col1  col3    sum0    6    15  45.0    77  137.01    1    15  45.0    57  117.02    2    14   0.2    42   56.23    3    12   6.0    37   55.04    4     9  85.0    27  121.05    5     5   1.0    15   21.0