0

我有以下简单的功能:

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 并让它为列表中的每个细分打印函数的结果(这是熊猫描述的),所以:

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 point 确实通过了,但它们没有被用作表选择的 ['SUBDIVISION'](函数的第 2 行),这就是为什么在两个块中描述中的数据是相同的。我知道我在范围方面做错了,但不知道是什么?

4

1 回答 1

1

改变

for subsm in subsl:
    sumsubdesc(table, subsm)
    print H4,subsm

for subsm in subsl:
    H4, subsm = sumsubdesc(table, subsm)
    print H4,subsm
于 2013-08-15T20:23:19.320 回答