【发布时间】:2015-10-12 19:20:15
【问题描述】:
谁能解释一下为什么在 python pandas 中使用 loc 并举例如下所示?
for i in range(0, 2):
for j in range(0, 3):
df.loc[(df.Age.isnull()) & (df.Gender == i) & (df.Pclass == j+1),
'AgeFill'] = median_ages[i,j]
【问题讨论】:
-
在您的示例中,使用
.loc主要是因为您尝试通过列索引AgeFill访问单元格。
标签: python pandas machine-learning