Skip to content

Instantly share code, notes, and snippets.

@pemagrg1
Last active July 9, 2019 06:31
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/c59d4291d4165c6d7e6ee8891b782d13 to your computer and use it in GitHub Desktop.
Save pemagrg1/c59d4291d4165c6d7e6ee8891b782d13 to your computer and use it in GitHub Desktop.
"""
Get total of each column values
"""
def totalcount(data):
return data.assign(Total=data.drop('Total', errors='ignore', axis=1).sum(1))
def pandas_get_total_row(df):
df = df.pipe(totalcount).T.pipe(totalcount).T
return df
df = pd.read_csv("<path to csv>")
df = pandas_get_total_row(df)
print(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment