Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. """
  2. Get total of each column values
  3. """
  4. def totalcount(data):
  5. return data.assign(Total=data.drop('Total', errors='ignore', axis=1).sum(1))
  6.  
  7. def pandas_get_total_row(df):
  8. df = df.pipe(totalcount).T.pipe(totalcount).T
  9. return df
  10.  
  11. df = pd.read_csv("<path to csv>")
  12. df = pandas_get_total_row(df)
  13. print(df)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement