利用xlrd读取excel 筛选0值超过99%的列,并删除 import xlrd workbook=xlrd.open_workbook(r"123.xlsx") table = workbook.sheet_by_name(‘Sheet1‘) nrows=table.nrows ncols=table.ncols del_col=[] for j in range(ncols) : sum = 0 for ai in table.col_values(j): if ai == 0.0 : sum+=1 if float(sum)/nrows>=0.99: del_col.append(j) print del_col
利用pandas读取excel 筛选0值超过99%的列,并删除
import pandas as pd df1=pd.read_csv(r"123.csv") df=pd.DataFrame(df1) nrows=df.shape[0] ncols=df.columns.size del_col=[] for j in range(ncols) : sum = 0 for ai in df.iloc[:,j]: if ai == 0.0 : sum+=1 if float(sum)/nrows>=0.99: del_col.append(j) print del_col