python - 两列的 Pandas Drop 功能不起作用
问题描述
我正在尝试使用 Pandas Drop 函数删除两列。但是,我收到错误。仅供参考,我已经打印了数据框的列名。为什么我会收到这样的错误?
在 [284] 中:Fulldf.columns
Out[284]:
Index(['PID', 'YearBuilt', 'YearRemodel', 'VeneerExterior', 'BsmtFinTp',
'BsmtFinSqft', 'BsmtUnfinSqft', 'HeatingQC', 'FstFlrSqft', 'SecFlrSqft',
'AbvGrndLiving', 'FullBathBsmt', 'HalfBathHouse', 'FullBathHouse',
'BdrmAbvGrnd', 'RmAbvGrnd', 'Fireplaces', 'GarageTp', 'GarageCars',
'GarageArea', 'WdDckSqft', 'OpenPrchSqft', 'LotArea', 'LotShape',
'BldgTp', 'OverallQuality', 'OverallCondition', 'SalePrice'],
dtype='object')
print(f'Total number of input variables to preprocess: {Fulldf.drop(['SalePrice', 'PID'], axis=1).shape[1]})
**strong text**
In [285]:
File "<ipython-input-287-7da1b9aca26a>", line 1
print(f'Total number of input variables to preprocess: {Fulldf.drop(['SalePrice', 'PID'], axis=1).shape[1]})
^
SyntaxError: invalid syntax
解决方案
您正在混合使用单引号和双引号。你能试试这个吗?
print(f"Total number of input variables to preprocess: {Fulldf.drop(['SalePrice', 'PID'], axis=1).shape[1]}")
推荐阅读
- android - onCreateOptionsMenu 中的 expandActionView 从操作栏中永久删除或隐藏其他菜单项
- javascript - Android重定向到另一个页面
- r - R将字符串转换为时间
- python - wget --content-disposition 使用 python
- javascript - 反应应用程序显示空白页
- c++ - 为什么这个变量被标记为“未使用”?
- amazon-web-services - Elastic Beanstalk 自定义 CloudWatch 日志
- python - 安装 Tweepy 时遇到问题
- java - 如何使用鼠标单击事件停止或继续循环?
- haskell - 没有单子转换器的单子的明确示例是什么?