Python,Excel——筛选

import pandas as pd
import numpy as np
data = pd.read_excel("C:/Users/Administrator/Desktop/19_初中_秋续寒.xlsx")
nrow= data.shape[0]
#print(nrow)
#print(data.values[0][1])

#a筛选的限定条件
a=[0,15,20,25,30,35,100]    #横条件
#七个数,单条件六次筛选过程,分别为[0,15),[15,20),[20,25),[25,30),[30,35),[35,100)

b=[0,0.65,0.7,0.75,0.85,0.95,2]   #竖条件
#单一条件_筛选
def select1():
    flag=0
    for m in range(0,nrow):
        if data.values[m][1]>=a[0] and  data.values[m][1]<a[1]:
            flag=flag+1
    return flag

#单一条件_变换_筛选
def select_1():
    result =[]
    for n in range(0,len(a)-1):
        flag=0
        for m in range(0,nrow):
            if data.values[m][1]>=a[n] and  data.values[m][1]<a[n+1]:
                flag=flag+1
        result.append(flag)
    return result

result=select_1()
print(result)
#双条件_双变换_筛选
def select2():
    result=[]
    for j in range(0,len(b)-1):
        for i in range(0,len(a)-1):  #变化a条件(第一个条件)
            flag=0
            for m in range(0,nrow):
                if data.values[m][1]>=a[i] and  data.values[m][1]<a[1+i] and data.values[m][2]>=b[j] and data.values[m][2]<b[j+1]:
                    flag=flag+1
            result.append(flag)
    return result

final=select2()
final = np.array(final).reshape(-1,len(a)-1)
#print(final)
df = pd.DataFrame(final)
df.to_csv('C:/Users/Administrator/Desktop/初中_19_秋续寒.csv', sep=',', mode='a',index = False,header = False)

在这里插入图片描述

发布了55 篇原创文章 · 获赞 17 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/weixin_43213658/article/details/88356268