marcevgen Asked:2020-03-26 21:20:32 +0000 UTC2020-03-26 21:20:32 +0000 UTC 2020-03-26 21:20:32 +0000 UTC 获取每一行的多列值的总和 772 大家好。表格有一个日期框架 |一|二|三|四| 第一|秒|三|123| 制作第五列代码 input['five'] = input['four'].sum() 如何更改代码,以使每一行都有给定三列一、二、三的总和? python 1 个回答 Voted Best Answer MaxU - stop genocide of UA 2020-03-28T01:57:45Z2020-03-28T01:57:45Z 例子: In [8]: df = pd.DataFrame(np.random.randint(10, size=(5, 4)), columns='one two three four'.split()) In [9]: df Out[9]: one two three four 0 3 1 2 5 1 2 5 2 1 2 5 1 3 9 3 5 6 7 2 4 9 6 0 2 In [10]: df['five'] = df[['one','two','three']].sum(axis=1) In [11]: df Out[11]: one two three four five 0 3 1 2 5 6 1 2 5 2 1 9 2 5 1 3 9 9 3 5 6 7 2 18 4 9 6 0 2 15
例子: