python - 如何根据熊猫中的条件删除一行,并将字符串转换为整数进行比较
问题描述
我正在尝试删除 Year Built 列中值小于 1920 的所有行。我不明白如何转换为整数,因此我可以评估不到 1920 年的建造条件,然后移除那些在 1920 年之前建造的建筑物。任何方向都值得赞赏!
没有错误:
YearBuilt_convert_to_integer = dframe[13].astype(int)
没有错误:
YearBuilt_less_than_1920 = YearBuilt_convert_to_integer < 1920
输出:
YearBuilt_less_than_1920
42 False
43 False
44 False
45 True
46 False
...
3533 False
3534 False
3535 False
3536 False
3537 False
Name: 13, Length: 3347, dtype: bool
产生 0 行:
dframe = dframe.loc[~dframe[13].astype(int)<1920, :]
0 1 2 3 4 5 6 7 8 9 ... 32 33 34 35 36 37 38 39 40 41
0 rows × 42 columns
解决方案
dframe[np.invert(dframe.loc[:,13].astype(int)<1920)]
推荐阅读
- angular - 如何在加载其余数据时在 Angular 中预加载一部分数据?
- json - 选择性读入 JSON 对象
- angular - 如何使用 ngIf 在 Angular 模板中定义变量,但使用类型?
- javascript - 获取用户可见的所有 html 控件?
- python-3.x - 循环遍历具有不同列表(在主列表中)长度的多个列表列表
- kernel - 如何在虚拟化环境中启用英特尔处理器跟踪 (IPT)?
- c# - 在 ASP.NET/C# 中,如何从数据库中获取数据到 CSS 样式表中?
- c - 使用 C 将数据集保存在 txt 文件中
- git - 第二个带有子模块的远程 git repo
- ms-access - 无法更改 MS Access 密码