使用drop函數(shù)可以刪除Python中指定的某幾行
importpandasaspd
importnumpyasnp
frompandasimportDataFrame
frompandasimportSeries
df1=DataFrame(
{"handsome":["timo","anni","timo"],
"smart":["mike","anni","mike"],
"beautiful":["lisa","tom","nike"]})
print(df1)
在drop函數(shù)后面用shift+tab可以查看函數(shù)的參數(shù)明細,如下:
默認參數(shù)axis=0,表示對行進行操作,如需對列進行操作需要更改默認參數(shù)為axis=1,
默認參數(shù)inplace=False,表示該刪除操作不改變原數(shù)據(jù),而是返回一個執(zhí)行刪除操作后的新dataframe,如需直接在原數(shù)據(jù)上進行刪除
操作,需要更改默認參數(shù)為inplace=True。
以上內容為大家介紹了python怎么刪某幾行,希望對大家有所幫助,如果想要了解更多Python相關知識,請關注IT培訓機構:千鋒教育。