HW6卡住
dtype_select = ['float64','int64']
print(dtype_select)
numeric_columns = list(app_train.columns[list(app_train.dtypes.isin(dtype_select))])
print(list(app_train.dtypes.isin(dtype_select)))
這樣寫,是不是有問題?
為什麼float64對應欄位的是TRUE,而int64對應欄位的是FALSE?
接下來為什麼程式跑到這行,會有error?
11 print("Numbers of remain columns" % len(numeric_columns))
12
13 # 檢視這些欄位的數值範圍
TypeError: not all arguments converted during string formatting
回答列表
-
2019/04/28 上午 10:40白學群贊同數:1不贊同數:0留言數:0
您好:
看樣子程式是沒有問題,目前我還在利用您的問題來debug ,
另外分享給您一個函數使用 Series.select_dtypes(include = ["您想要選取的資料格式"]),基本上這個函數會比較好使用喔!!
希望有幫助到您~
(至於您的問題我有抓到問題點會再回復您)
-
2019/04/28 下午 03:45凌璟騰贊同數:1不贊同數:0留言數:0
第二個問題我發現是範例本來就少了一個 %d ,應該改成
print("Numbers of remain columns %d"%len(numeric_columns))
-
2019/04/28 下午 06:15張維元 (WeiYuan)贊同數:1不贊同數:0留言數:0
這個錯誤的原因在於:
```
print("Numbers of remain columns"%len(numeric_columns))
```
格式化字串的左邊找不到對應的 %s 做抽換。
-
2019/04/30 上午 05:27童子函贊同數:不贊同數:留言數:
問題在於app_train.dtypes的資料型態並不是string
透過print(app_train.dtype[0:10])可以看到
再以type(app_train.dtype[0])可以看到資料型態為:<class 'numpy.dtype'>
因此得知app_train.dtype中的數值並非str,數字直接打,字串透過加上引號('str')來得到
而<class 'numpy.dtype'>則透過np.dtype()來得到
所以
dtype_select = [np.dtype(np.int64)]
print(app_train.dtypes.isin(dtype_select)[0:10])
就可以得到想要的結果了
不過我也是python的初學者,如果有甚麼觀念上的錯誤可以一起來討論 : )