import pandas as pd
import numpy as np
from pandas import DataFrame
from pandas import Series
df1= DataFrame(
{"handsome":["timo","anni","timo"],
"smart":["mike","anni","mike"],
"beautiful":["lisa","tom","nike"]})
print(df1)
handsome smart beautiful 0 timo mike lisa 1 anni anni tom 2 timo mike nike
1、df.drop(["列名"],axis=1)
df1.drop(["handsome","smart"],axis=1)#删除列名为handsome和smart的整列
2、df.drop(columns=["列名"])
df1.drop(columns=["handsome","smart"])#删除列名为handsome和smart的整列
3、df.drop([0,1])
df1.drop([0,1])#删除索引为0、1的整行
4、小结:
在drop函数后面用shift+tab可以查看函数的参数明细,如下:
默认参数axis=0,表示对行进行操作,如需对列进行操作需要更改默认参数为axis=1,
默认参数inplace=False,表示该删除操作不改变原数据,而是返回一个执行删除操作后的新dataframe,如需直接在原数据上进行删除操作,需要更改默认参数为inplace=True
df1.drop(labels=None, axis=0, index=None, columns=None, level=None, inplace=False, errors='raise')