logo
Loading...

想請問老師如何解決'DataFrame' object has no attribute 'dtype'問題? 查了一些資料大略了解:DataFrame.dtypes is an attribute to list data types, for series it's a dtype - Cupoy

import pandas as pdimport numpy as npfrom sklearn....

想請問老師如何解決'DataFrame' object has no attribute 'dtype'問題? 查了一些資料大略了解:DataFrame.dtypes is an attribute to list data types, for series it's a dtype

2021/02/02 下午 04:49
數值型特徵 - 去除離群值
林鈺鈞
觀看數:836
回答數:2
收藏數:0

import pandas as pd import numpy as np from sklearn.preprocessing import MinMaxScaler from sklearn.model_selection import cross_val_score from sklearn.linear_model import LinearRegression data_path = 'D:\Machine Learning' df_train = pd.read_csv('house_train.csv') train_Y = np.log1p(df_train['SalePrice']) df = df_train.drop(['Id', 'SalePrice'] , axis=1) #df.head() #只取 int64, float64 兩種數值型欄位, 存於 num_features 中 num_feature=[] for dtype,feature in zip(df.dtype,df.columns): if dtype=="float64" or dtype=="int64": num_feature.append(feature) print(f'{len(num_features)} Numeric Features : {num_features}\n')

回答列表

  • 2021/02/02 下午 05:35
    李柏霆
    贊同數:0
    不贊同數:0
    留言數:0

    for dtype,feature in zip(df.dtype**s**,df.columns): >>>df.dtype**s** 少了一個s

  • 2021/02/02 下午 10:37
    張維元 (WeiYuan)
    贊同數:0
    不贊同數:0
    留言數:0

    嗨,你好
    下次請把錯誤訊息放在內文,不要只放在標題。 「'DataFrame' object has no attribute 'dtype'」意思是 DataFrame 找不到 dtype 方法,因為在 DataFrame 的方法是 dtypes 才對。

    嗨,你好,我是維元,持續在不同的平台發表對 #資料科學、 #網頁開發 或 #軟體職涯 相關的文章。如果對於內文有疑問都歡迎與我們進一步的交流,都可以追蹤我的 Facebook技術部落格 ,也會不定時的舉辦分享活動,一起來玩玩吧 ヽ(●´∀`●)ノ 以下分享一些我近期發表跟資料科學有關的文章,歡迎大家持續追蹤: ■ 資料分析工具那麼多,該怎麼選? 🛠️
    真.資料團隊與分工
    觀察資料的 N 件事 🔖
    資料前處理必須要做的事 - 資料清理與型態調整