亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

列表對象沒有屬性列

列表對象沒有屬性列

慕娘9325324 2024-01-15 15:45:02
我正在嘗試對簡單數據集執行最小-最大縮放data2 = [10, 20, 35, 70, 100]以下代碼給我一個錯誤AttributeError:“列表”對象沒有屬性“列”def min_max_scaling(df):df_norm = df.copy()for col in df_norm.columns:    df_norm[col] = (df_norm[col] - df_norm[col].min()) / (df_norm[col].max() - df_norm[col].min())return df_normdf_normalized = min_max_scaling(data3)df_normalized
查看完整描述

1 回答

?
隔江千里

TA貢獻1906條經驗 獲得超10個贊

您的 min_max_scaling 函數需要一個 pandas dataframe 實例,但您向它傳遞了一個列表。按如下方式更改代碼應該可行。


import pandas as pd


def min_max_scaling(df):

    df_norm = df.copy()

    for col in df_norm.columns:

        df_norm[col] = (df_norm[col] - df_norm[col].min()) / (df_norm[col].max() - df_norm[col].min())

    

    return df_norm


data2 = [10, 20, 35, 70, 100]


data2 = pd.DataFrame(data2)


df_normalized = min_max_scaling(data2)


print(df_normalized)


查看完整回答
反對 回復 2024-01-15
  • 1 回答
  • 0 關注
  • 140 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號