我认为您已经误解了某些python语法,以下代码执行了两项任务:
In [11]: a = b = 1In [12]: aOut[12]: 1In [13]: bOut[13]: 1
因此,在您的代码中就好像您在做的一样:
sum = df['budget'] + df['actual'] # a Series# anddf['variance'] = df['budget'] + df['actual'] # assigned to a column
后者为df创建了一个新列:
In [21]: dfOut[21]: cluster date budget actual0 a 2014-01-01 00:00:00 11000 100001 a 2014-02-01 00:00:00 1200 10002 a 2014-03-01 00:00:00 200 1003 b 2014-04-01 00:00:00 200 3004 b 2014-05-01 00:00:00 400 4505 c 2014-06-01 00:00:00 700 10006 c 2014-07-01 00:00:00 1200 10007 c 2014-08-01 00:00:00 200 1008 c 2014-09-01 00:00:00 200 300In [22]: df['variance'] = df['budget'] + df['actual']In [23]: dfOut[23]: cluster date budget actual variance0 a 2014-01-01 00:00:00 11000 10000 210001 a 2014-02-01 00:00:00 1200 1000 22002 a 2014-03-01 00:00:00 200 100 3003 b 2014-04-01 00:00:00 200 300 5004 b 2014-05-01 00:00:00 400 450 8505 c 2014-06-01 00:00:00 700 1000 17006 c 2014-07-01 00:00:00 1200 1000 22007 c 2014-08-01 00:00:00 200 100 3008 c 2014-09-01 00:00:00 200 300 500
顺便sum
说一句,您不应将其用作变量名称,因为它会覆盖内置的sum函数。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)