我是新来的,经过很多研究,还没能破解这个。你知道吗
我的列表有点像这样:
lister=["AB1","AB2","AB3","AB3-2","AB3-3","AB3-4","AB4","AB4-2","AB5"]
它是现有文件夹的列表,不能更改为更实用的文件夹。 我还将此列表与其他一些值一起作为一列。你知道吗
目标是让具有“-2”、“-3”、“-#”的元素只使用具有最大值的元素。这些“-#”值最多可达10。你知道吗
上述清单的结果是:
resulter=["AB1","AB2","AB3-4","AB4-2","AB5]
非常感谢你的帮助!你知道吗
更新:
约翰·兹温克的答案对名单有用。然而,当我尝试在熊猫数据帧上使用它时,它会给我错误。因此,重新审视我的问题可能更有帮助:
我的数据帧如下所示:
COL1 COL2 COL3 COL4 COL5 COL6
0 1 77 AB1 0.609856 2.145556 2.115333
1 2 77 AB2 0.603378 2.146333 2.125667
2 3 77 AB3 0.600580 2.150667 2.135000
3 4 89 AB1 0.609129 2.149056 2.097667
4 5 89 AB2 0.604061 2.175333 2.142667
5 6 89 AB3 0.606987 2.139944 2.107333
6 7 89 AB4 0.603696 2.122000 2.102000
7 8 94 AB1 0.606438 2.156444 2.142000
8 9 94 AB1-2 0.611260 2.133556 2.095000
9 10 94 AB2 0.596059 2.169056 2.137333
在这种情况下,我的要求是基于COL3(AB1)的值删除第7行,因为第8行中存在AB1-2值。你知道吗
再次感谢!你知道吗
这不是最好的答案,我认为它的性能很差,但是如果有人需要没有任何模块的纯python或者使用Cython(类型化变量),这可能会有帮助:
给你:
然后:
给你:
相关问题 更多 >
编程相关推荐