我需要更改代码以使用NumPy
2D数组而不是pandas
数据帧:
df = pd.DataFrame(data=np.array([[nan, 2, 3], [4, 5, 6], [7, 8, 9]]), columns=["col1", "col2", "col3"])
list_of_NA_features = ["col1"]
for feature in list_of_NA_features:
for index,row in df.iterrows():
if (pd.isnull(row[feature]) == True):
missing_value = 5 # for simplicity, let's put 5 instead of a function
df.ix[index,feature] = missing_val
对for index,row in df.iterrows():
、pd.isnull(row[feature]) == True
和df.ix[index,feature] = missing_val
数组的正确方法是什么?你知道吗
这就是我目前所做的:
np_arr = df.as_matrix
for feature in list_of_NA_features:
for feature in xrange(np_arr.shape[1]):
# ???
如何获取行的索引以执行np_arr[irow,feature]
?另外,给NumPy
数组中的特定行和列赋值的正确方法是什么:df.ix[index,feature] = missing_val
?你知道吗
更新
我通过删除函数fill_missing_values
并用值5
替换它来简化代码。然而,在我的实际案例中,我需要估计丢失的值。你知道吗
设置
解决方案:
相关问题 更多 >
编程相关推荐