执行以下操作后,我有以下数据框:
train_X = icon[['property', 'room', 'date', 'month', 'amount']]
train_frame = train_X.groupby(['property', 'month', 'date', 'room']).median()
print(train_frame)
amount
property month date room
1 6 6 2 3195.000
12 3 2977.000
18 2 3195.000
24 3 3581.000
36 2 3146.000
3 3321.500
42 2 3096.000
3 3580.000
54 2 3195.000
3 3580.000
60 2 3000.000
66 3 3810.000
78 2 3000.000
84 2 3461.320
3 2872.800
90 2 3461.320
3 3580.000
96 2 3534.000
3 2872.800
102 3 3581.000
108 3 3580.000
114 2 3195.000
我的目标是根据我这样做的(房产、月份、日期、房间)跟踪中位数金额:
big_list = [[property, month, date, room], ...]
test_list = [property, month, date, room]
if test_list == big_list:
#I want to get the median amount wrt to that row which matches the test_list
我该怎么做呢?
我所做的是,尝试了以下...
count = 0
test_list = [2, 6, 36, 2]
for j in big_list:
if test_list == j:
break
count += 1
现在,在获得计数后,如何通过数据帧中的计数访问中位数?他们是一种按索引访问数据帧的方法吗?
请注意:
big_list 是列表的列表,其中每个列表都是来自上述数据框的 [property, month, date, room]
test_list 是与 big_list 匹配的传入列表,以防万一。
蓝山帝景
收到一只叮咚
阿晨1998
随时随地看视频慕课网APP
相关分类