row port dataframe cti rand 數據處理 tro afr word

from pandas import Series,DataFrame
import pandas as pd
import numpy as np

python中pandas.DataFrame對行與列求和及添加新行與列示例

df = DataFrame(np.random.randn(4, 5), columns=[‘A‘, ‘B‘, ‘C‘, ‘D‘, ‘E‘])
df[‘Col_sum‘] = df.apply(lambda x: x.sum(), axis=1)
df.loc[‘Row_sum‘] = df.apply(lambda x: x.sum())

python pandas 數據處理