我有这个房地产数据:
neighborhood type_property type_negotiation price
Smallville house rent 2000
Oakville apartment for sale 100000
King Bay house for sale 250000
...
Run Code Online (Sandbox Code Playgroud)
我创建了一个函数,通过您输入的邻域对这个大数据集进行排序,如果它是一个待售房屋,然后返回这些房屋的第10和第90百分位数和数量.我在下面有这个:
def foo(string):
a = df[(df.type_negotiation == 'forsale')&(df.type_property == 'house')&(df.neighborhood == string)]
b = pd.DataFrame([[a.price.quantile(0.1), a.price.quantile(0.9), len(a.index)]],
columns=('tenthpercentile', 'ninetiethpercentile', 'Quantity'))
return b
print(foo('KingBay'))
tenthpercentile ninetiethpercentile Quantity
0 250000.0 250000.0 1
Run Code Online (Sandbox Code Playgroud)
我想编写一个循环来为我所拥有的邻域列表执行此操作,然后在一个帧中编译新数据中的每个返回.看起来像这样:
tenthpercentile ninetiethpercentile Quantity
King Bay 250000.0 250000.0 1
Smallville 99000.0 120000.0 8
Oakville 45000.0 160000.0 6
Run Code Online (Sandbox Code Playgroud)
先感谢您.