利用xlrd读取excel筛选0值超过99%的列,并删除import xlrdworkbook=xlrd.open_workbook(r"123.xlsx")table = workbook.sheet_by_name(‘Sheet1‘)nrows=table.nrowsncols=table.ncolsdel_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 pddf1=pd.read_csv(r"123.csv")df=pd.DataFrame(df1)nrows=df.shape[0]ncols=df.columns.sizedel_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 |
原文地址:https://www.cnblogs.com/52circle/p/8540673.html
时间: 2024-10-13 06:23:29