繁体   English   中英

删除列后 Df.shape 不调整

[英]Df .shape not adjusting after dropping columns

我对 Python 和 Jupyter Notebooks 非常陌生,所以请多多包涵,但经过深入研究后,我无法解决这个问题。

使用.drop 删除几列后,我没有看到.shape 中反映的变化。

使用 drop 后的结果,但形状 output 没有反映

df 开始为 1404 x 68,在执行后。drop output 说 1404 x 38,但是当我 run.shape 它跳回 1404 x 68。

df_realestate.drop(['Zoning Class', 'Lot Shape', 'Lot Config', 'Land Slope', 'Bldg Type', 
                                   'House Style', 'Roof Style', 'Roof Material', 'Exterior Primary', 'Masonry/Veneer', 'Exterior Qual', 'Exterior Cond',
                                   'Foundation', 'Basement Height', 'Basement Cond', 'Basement Exposure', 'Basement Finish', 'Heating Qual', 'CentralAir', 
                                   'Electrical', 'Functionality', 'Fireplce Qual', 'Garage Type', 'Garage Qual', 'Garage Cond', 'Paved Drive',
                                   'Pool Qual', 'Fence', 'Sale Type', 'Year Remod Add'], axis = 1)

df_realestate.shape

谢谢你的帮助。 我敢肯定这是我想念的简单东西。

是的。 像大多数 pandas API 一样, drop方法不会在适当的位置进行操作。 相反,它会返回一个修改后的 DataFrame,您正在丢弃它。

您可以添加inplace=True作为参数,也可以添加

df_realestate = df_realestate.drop(...)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM