python - 使用 iloc 创建新 col 和设置值时出错
问题描述
for i in range(0, len(df)):
df.iloc[i,'county'] = get_county(df.iloc[i]['latitude'], df.iloc[i]['longitude'])
我正在尝试通过循环遍历数据框来创建一个名为county 的新列。这给了我一个错误IndexError: only integers, slices (
::), ellipsis (
...), numpy.newaxis (
无) and integer or boolean arrays are valid indices
是否无法使用在新列中设置值df.iloc[i,'newcolname']
?
解决方案
推荐阅读
- java - 拒绝对先前失败的类 java.lang.Class 重新初始化
: java.lang.NoClassDefFoundError - mysql - 检查mysql中重复行上是否存在值
- wordpress - 为什么我在 Wordpress Contact Form 7 上收到文件上传错误?
- c# - 使用作为参数传递给内部匿名函数C#中的函数的对象
- javascript - 使用javascript从数组中提取数据
- javascript - 我如何插入相同的(其中包含我的菜单)到所有其他 html 页面?
- python - RNN 模型只预测一个类别?
- security - 授权导入范围后是否可以浏览电子表格?
- html - 如何在 HTML 中设置两个内联图像?
- android - 在彼此之上实现多个视图的正确方法是什么?