參考: Python: pandas.DataFrame.astype函数方法的使用

舉例:

df1.astype( dtype = np.float64, errors = “ignore”)

df1.astype(dtype= np.float64)
#沒有設定errors參數,預設值為”raise”
ValueError: could not convert string to float: ‘Freq_12000_MHz_H_Amp’
則只能對1D 的資料做處理
若對 DataFrame處理
會出現
TypeError: arg must be a list, tuple, 1-d array, or Series
numpy.ndarray的astype() :

容易誤會 str(a)能將
array所有元素轉為字串
需使用 a.astype(str)
a.astype(object) 也可
a.astype(np.object)雖然可以跑
但會出現np.object已經廢棄的警告訊息
建議單獨使用object即可
推薦hahow線上學習python: https://igrape.net/30afN





![Python: Regular Expression 正規表示法 正則表達式 import re ; pattn = “[\d]{4}\/[01][\d]\/[0123][\d] [\d]{6}” ; match = re .search (pattn,text) .group() Python: Regular Expression 正規表示法 正則表達式 import re ; pattn = “[\d]{4}\/[01][\d]\/[0123][\d] [\d]{6}” ; match = re .search (pattn,text) .group()](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2022/09/20220901154435_19.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

![Python: matplotlib繪圖,如何限定座標軸範圍? plt.axis([xmin, xmax, ymin, ymax]) Python: matplotlib繪圖,如何限定座標軸範圍? plt.axis([xmin, xmax, ymin, ymax])](https://i2.wp.com/savingking.com.tw/wp-content/uploads/2023/02/20230208101745_93.jpg?quality=90&zoom=2&ssl=1&resize=350%2C233)
![Python: 如何使用numpy.newaxis 增加資料的維度? y = x[:, np.newaxis] Python: 如何使用numpy.newaxis 增加資料的維度? y = x[:, np.newaxis]](https://i0.wp.com/savingking.com.tw/wp-content/uploads/2023/03/20230313184351_57.png?quality=90&zoom=2&ssl=1&resize=350%2C233)

近期留言