How to sum the total sum from two other columns

Viewed 75

I have this a df with some columns. I could get the total sum of column ['Profit'] and ['Commission']. I am trying to get a new column ['Net Profit'] of the total sum from column ['Profit'] and ['Commission'] but I could get only a concatenation of lists or a sum of each row in the column

    gross_profit = [df['Profit'].sum()]
    commissions = [df['Commission'].sum()]

What I tried:

    df['net_profit'] = df['Profit'] + df['Commission']
    df['net_profit'] = df['Profit'].sum() + df['Commission'].sum()

By the way, how one can get a total sum of an Excel column in Python without going through Pandas?

Thank you.

1 Answers

The easiest way to achieve this is to create a new column

df['net_profit'] = df['Profit'] + df['Comission']

df_describe = df.describe()

The df_describe data frame will have the sum as an entry for the column 'net_profit'. It will additionally have other statistics like mean, min, max, and percentiles.

Related