Python uses pandas and xlrd to read Excel, feature filtering deletes columns with 0 values over 99%

Source: Internet
Author: User

Using XLRD to read Excel
Filter 0 columns with a value greater than 99% and remove

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
Using Pandas to read Excel
Filter 0 columns with a value greater than 99% and remove

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 JinchRange (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


Python uses pandas and xlrd to read Excel, feature filtering deletes columns with 0 values over 99%

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.