我有一个数据框(
training_df
)有4列,每列包含约150行。我还具有以下功能:
def normalise(theMin, theMax, theVal):
if(theMin == theVal):
return 0
else if(theMax == theVal):
return 1
return (theVal - theMin) / (theMax - theMin)
现在,我想做的是依次遍历我的数据帧的所有四列,遍历每列中的所有行,对于行中的每个值(当然每行中只有一个单元格),我想用从
normalise
作用因此,我通过查看本论坛中已经提出的问题,尝试了类似的方法:
for column in training_df:
theMin = training_df[column].min()
theMax = training_df[column].max()
for i in training_df[[column]].iterrows():
training_df[[column[i]]] = normalise(theMin, theMax, i)
但我有一个
TypeError: string indices must be integers
我对Python和pandas以及数据挖掘非常陌生,所以如果有人能澄清一下这一点,我会非常感激。提前谢谢。