Skip to content

Instantly share code, notes, and snippets.

@pemagrg1
Created July 9, 2019 06:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pemagrg1/f587d7732fdc6ac449ac07fd1da2ec62 to your computer and use it in GitHub Desktop.
Save pemagrg1/f587d7732fdc6ac449ac07fd1da2ec62 to your computer and use it in GitHub Desktop.
def get_total(df):
df.loc['Total'] = pd.Series(df['Marks'].sum(), index = ['Marks'])
return df
df = pd.DataFrame({'Subjects': ["Maths","Science","English"], 'Marks': [80,90,75]})
df = df.reindex(columns=['Subjects','Marks'])
df = get_total(df)
df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment