鱼C论坛

 找回密码
 立即注册
查看: 2441|回复: 2

在多列单元格中随机抽取N个单元格

[复制链接]
发表于 2021-3-27 01:15:50 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x

非常感谢你在百忙之中抽空为我解答。
以下是两列和三列单元格中随机抽取N个单元格的算法,如果要在四列,五列中随机抽取N个单元格该怎么改?
def check(sample,data2,index,around):  #在两列中抽取
    res=[]
    for i in sample:
        if around!=-1:
            temp=[j  for j in data2 if i[index[0]]==j[index[0]] and abs(i[index[1]]-j[index[1]])<=around]
        else:
            temp=[j  for j in data2 if i[index[0]]==j[index[0]] and i[index[1]]==j[index[1]]]
        if len(temp):
            res.append(temp[0])
        else:
            break
    else:
        return(res)
    return([])

def check(sample,data2,index,around): #在三列中抽取
    res=[]
    for i in sample:
        if around!=-1:
            temp=[j  for j in data2 if i[index[0]]==j[index[0]] and i[index[1]]==j[index[1]] and abs(i[index[2]]-j[index[2]])<=around]
        else:
            temp=[j  for j in data2 if i[index[0]]==j[index[0]] and i[index[1]]==j[index[1]] and i[index[2]]==j[index[2]]]
        if len(temp):
            res.append(temp[0])
        else:
            break
    else:
        return(res)
    return([])

以下是四列和五列:
def check(sample,data2,index,around): #在四列中抽取


def check(sample,data2,index,around): #在五列中抽取
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-3-27 07:14:04 From FishC Mobile | 显示全部楼层
这个函数4个参数,你都不说一下,谁能看懂你这些代码
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2021-3-27 12:43:54 | 显示全部楼层
本帖最后由 阿智兄 于 2021-3-28 02:44 编辑

谢谢你的回复。
问题解决了,谢谢。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-26 02:47

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表