這篇文章給大家分享的是有關(guān)python3函數(shù)中astype的使用方法的內(nèi)容。小編覺得挺實用的,因此分享給大家做個參考。一起跟隨小編過來看看吧。
astype實現(xiàn)變量類型轉(zhuǎn)換:
astype(type): returns a copy of the array converted to the specified type. a = a.astype('Float64') b = b.astype('Int32')
Python中與數(shù)據(jù)類型相關(guān)函數(shù)及屬性有如下三個:type/dtype/astype
type() 返回參數(shù)的數(shù)據(jù)類型
dtype 返回數(shù)組中元素的數(shù)據(jù)類型
astype() 對數(shù)據(jù)類型進(jìn)行轉(zhuǎn)換
你可以使用 .astype() 方法在不同的數(shù)值類型之間相互轉(zhuǎn)換。a.astype(int).dtype # 將 a 的數(shù)值類型從 float64 轉(zhuǎn)換為 int,
在 Python 內(nèi)建對象中,數(shù)組有三種形式:
列表:[1, 2, 3]
元組:(1, 2, 3, 4, 5)
字典:{A:1, B:2}
感謝各位的閱讀!關(guān)于python3函數(shù)中astype的使用方法就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!