我有以下简单的功能:
def sumsubdesc(table,subs):
H2=table[(table['SUBDIVISION']==subs)&(table['AREA']=='260B')]
H3=H2[['LIST_PRICE','SOLD_PRICE']]
H4=H3.describe()
return H4 , subs
以下的潜艇名单:
subsl=['EAGLE POINT','HEATHERWOOD']
我想调用sumsubdesc并让它打印列表中每个细分的函数结果(这是pandas描述的) 这样:
for subsm in subsl:
sumsubdesc(table, subsm)
print H4,subsm
给出了:
LIST_PRICE SOLD_PRICE
count 355.000000 166.000000
mean 438701.030986 397962.518072
std 116994.150714 106734.004085
min 164900.000000 150200.000000
25% 359450.000000 330375.000000
50% 429900.000000 380000.000000
75% 499900.000000 458986.500000
max 873240.000000 898492.000000 EAGLE POINT
LIST_PRICE SOLD_PRICE
count 355.000000 166.000000
mean 438701.030986 397962.518072
std 116994.150714 106734.004085
min 164900.000000 150200.000000
25% 359450.000000 330375.000000
50% 429900.000000 380000.000000
75% 499900.000000 458986.500000
max 873240.000000 898492.000000 HEATHERWOOD
请注意,Heatherwood和Eagle点的名称确实已通过,但它们不会被用作表选择的['SUBDIVISION'](函数的第2行),这就是为什么描述中的数据相同的原因两个街区。我知道我在做范围有问题,但不知道是什么?
答案 0 :(得分:1)
更改
for subsm in subsl:
sumsubdesc(table, subsm)
print H4,subsm
到
for subsm in subsl:
H4, subsm = sumsubdesc(table, subsm)
print H4,subsm