Column pandas on how to use the library in python delete contains a null value after reading excel spreadsheet

After using pandas to read the relevant excel, columns, how to clean it if null values in the table
after access to the relevant information online, has been way

pandas.dropna(axis=1,how=‘any’)

axis = 0 refers to the line, if not write parameter, the default is the axis = 0,
Axis refers to the column. 1 =

how = 'any' refers to long column containing a null value, deletes the column
how = 'all' is the only representative of a null value as a whole, the column was deleted

Note that the version in python3.7
to receive the return value pandas.dropna need to have a variable
or when running the program without error but the data change will not happen


Some write about the pandas library operations excel spreadsheet

#encoding=gb18030
import numpy
import pandas as pd
data_filename = "data/data21695/数据.xlsx"
df = pd.read_excel(data_filename)
x = df.dropna(axis=1,how='any')
g=df["编号"]
y = len(g)
i=0
print(y)
del x["无机盐"]
x["无敌"]=x["身高"]
for i in range(y):
    x.iloc[i,0]=i

x.to_excel('new.xlsx')

pandas.read_excel read excel spreadsheet

del [ 'inorganic salts'] delete a column called inorganic salt

X [ 'unrivaled'] = x [ 'height'] add an unrivaled named, copy the data to the height of the column of this row unrivaled

x.iloc [i, 0] obtaining the i-th row, the data in column 0

x.to_excel introduced into the excel spreadsheet named new.xlsx

Released two original articles · won praise 1 · views 79

Guess you like

Origin blog.csdn.net/weixin_43209227/article/details/104482630