python - KeyError: 0 in pandas
问题描述
waste['GDP ($M)'] - my column in a table Table 'waste' consist of 161 rows Error is on the 3 line (with condition). It the table 'True" values are exist, but I can't understand where is the problem. What should I change in my code?
Also, I changed values in a table from Scientific Notation to float, due to this my NaN values changed to "nan"
column = pd.isna(waste['GDP ($M)'])
gdp_nan = []
for row in range(len(waste)):
if column[row] == True:
gdp_nan.insert(row, row)
print(gdp_nan)
解决方案
As it was said in the comments, change range(2, len(waste)) Then, I had KeyError 21, which means that 21 record doesn't exist. You should reindex your dataframe.
waste = waste.reset_index(drop = True)
right in this way, then loop will work well
推荐阅读
- ios - 如何在响应所有设备的 react-native 应用程序中设置 marginLeft 和 marginRight
- python - Python 中的正则表达式,用于检测整数、浮点数或科学记数法中的数字
- python - 圆上的非最大值抑制
- javascript - 为什么在此反应代码中释放外部 div 时不会触发 mouseup 事件(使用 window.addEventListener)
- android - recyclerview 无法同步或创建
- python - 使用 opencv_createsamples 时出现“无效的背景描述文件”
- sdl-2 - 我需要设置哪些标志才能将 libwebp-1.0.0 与提供的外部库静态链接?
- node.js - Express、Passport-Google、React - 维护正确的会话信息
- activemq-artemis - 无法运行 Artemis 附带的示例
- sql - 使用 CAST 对 XML 进行 DISTINCT