Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

pandas ttable with sum totals

import numpy as np
import pandas as pd


df = pd.DataFrame({'a': [10,20],'b':[100,200],'c': ['a','b']})

df.loc['Column_Total']= df.sum(numeric_only=True, axis=0)
df.loc[:,'Row_Total'] = df.sum(numeric_only=True, axis=1)

print(df)

                 a      b    c  Row_Total
0             10.0  100.0    a      110.0
1             20.0  200.0    b      220.0
Column_Total  30.0  300.0  NaN      330.0
Comment

PREVIOUS NEXT
Code Example
Python :: split filename and extension python 
Python :: python ceiling 
Python :: pandas sample rows 
Python :: append dataframe to another dataframe 
Python :: downgrade pip 
Python :: python detect internet connection 
Python :: python for looop array value and index 
Python :: python pygame key input 
Python :: python flat list from list of list 
Python :: selenium close browser 
Python :: sigmoid function numpy 
Python :: python fiscal year prior 
Python :: oddlyspecific09123890183019283 
Python :: django serializer exclude fields 
Python :: Sin , Cos Graph using python turtle. 
Python :: how to change opencv capture resolution 
Python :: check iterable python 
Python :: pyspark import stringtype 
Python :: pygame python3.8 
Python :: py random list integers 
Python :: np.random.seed 
Python :: download youtube video in python 
Python :: pandas to_csv delimiter 
Python :: what is nea in python 
Python :: convert dtype of column cudf 
Python :: cut 0s on string python 
Python :: group consecutive numbers in list python 
Python :: how to make a pairs plot with pandas 
Python :: x= [10] def List_ex(): x.append(20) def add_list(): x=[30,40] x.append(50) print (x) List_ex() print (x) add_list() print (x) 
Python :: iterating over 2d array python 
ADD CONTENT
Topic
Content
Source link
Name
8+6 =