python模糊查询reslist_组Python列表元素

博客内容讲述了如何对一个包含三元组的Python列表进行排序,并根据特定规则转换为新的二维列表。通过使用`operator.itemgetter`进行排序,然后利用numpy进行切片和重塑,最终得到期望的结果。
摘要由CSDN通过智能技术生成

I have a python list as follows:

my_list =

[[25, 1, 0.65],

[25, 3, 0.63],

[25, 2, 0.62],

[50, 3, 0.65],

[50, 2, 0.63],

[50, 1, 0.62]]

I want to order them according to this rule:

1 --> [0.65, 0.62]

2 --> [0.62, 0.63]

3 --> [0.63, 0.65]

So the expected result is as follows:

Result = [[0.65, 0.62],[0.62, 0.63],[0.63, 0.65]]

How to do it guys?

I tried as follows:

df = pd.DataFrame(my_list,columns=['a','b','c'])

res = df.groupby(['b', 'c']).get_group('c')

print res

ValueError: must supply a tuple to get_group with multiple grouping keys

解决方案

You can sort your list with native python, but I find it easiest to get your required list using numpy. Si

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值