使用 .loc[] 提取行时出现 keyerror
getting keyerror while extracting rows using .loc[]
我正在尝试使用 .loc[]
从数据框中提取行,但出现此错误:
KeyError: 'Passing list-likes to .loc or [] with any missing labels is no
longer supported, see https://pandas.pydata.org/pandas-
docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike'
我的代码是:
new_data = pd.get_dummies(data,drop_first=True)
features = list(set(data.columns)-set(['Price']))
x = new_data.loc[:,features].astype(float)
请给我一个简单的答案或者我能理解的方式,因为我是新手。
这个怎么样:
features = set(data.columns.drop('Price'))
x = new_data.loc[:,features].astype(float)
我正在尝试使用 .loc[]
从数据框中提取行,但出现此错误:
KeyError: 'Passing list-likes to .loc or [] with any missing labels is no
longer supported, see https://pandas.pydata.org/pandas-
docs/stable/user_guide/indexing.html#deprecate-loc-reindex-listlike'
我的代码是:
new_data = pd.get_dummies(data,drop_first=True)
features = list(set(data.columns)-set(['Price']))
x = new_data.loc[:,features].astype(float)
请给我一个简单的答案或者我能理解的方式,因为我是新手。
这个怎么样:
features = set(data.columns.drop('Price'))
x = new_data.loc[:,features].astype(float)