【发布时间】:2022-10-12 22:00:18
【问题描述】:
我正在尝试在应用过滤器后根据单元格值进行计算。我以前从未遇到过这个问题,突然之间它似乎是一个问题,我不知道我必须这样做。
transacties_klant DataFrame:
crm_ref year quarter LitersSold
3 V000095 20 1.0 60.00
4 V000095 20 3.0 180.00
5 V000095 21 2.0 360.00
6 V000095 21 3.0 11.20
7 V000095 21 4.0 649.04
8 V000095 22 1.0 1107.00
9 V000095 22 2.0 3100.80
10 V000095 22 3.0 2164.20
此代码的输出应该是包含浮点数的变量,但它返回的是?系列,数据框,多索引?
last_quarter_year = 22
last_quarter = 2
last_quarter_sum = transacties_klant[(transacties_klant['year']==last_quarter_year) & (transacties_klant['quarter']==last_quarter)]['LitersSold']
quarter_before_sum = transacties_klant[(transacties_klant['year']==(last_quarter_year-1)) & (transacties_klant['quarter']==last_quarter)]['LitersSold']
print(last_quarter_sum)
但是当前的输出是这样的:
9 3100.8
Name: LitersSold, dtype: float64
我已经尝试过 .astype() 和 .values()。 我需要改变什么last_quarter_sum= 3100.8 ?
【问题讨论】: