Here is one way using **[`df.pivot_table()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.pivot_table.html)**: Replace any other party except `Bharatiya Janata Party` as `Others` using [`np.where()`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.where.html) and then use `pivot_table`, finally get [`sum()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.sum.html) across `axis=1` for sum of votes. df1=(df.assign(party=np.where(df.party.ne('Bharatiya Janata Party'),'Others',df.party)). pivot_table(index='state',columns='party',values='votes',aggfunc='sum')) ---------- Another method with [`crosstab()`](https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.crosstab.html) similar to `pivot_table`: df1=pd.crosstab(df.state,np.where(df.party.ne('Bharatiya Janata Party'),'Others',df.party) ,df.votes,aggfunc='sum') ---------- Finally, getting the Total and `reset_index()`: df1=df1.assign(Total=df1.sum(axis=1)).reset_index().rename_axis(None,axis=1) ---------- **Output:** (*Note: I had added dummy `Andhra Pradesh` rows for testing*) state Bharatiya Janata Party Others Total 0 Andaman & Nicobar Islands 90969 90954 181923 1 Andhra Pradesh 100 85 185 You can opt to delete the `Others` column later : `df1=df1.drop('Others',1)`