我正在尝试规范化数据框的一列,该列也包含None值,如何使用lambda函数来做到这一点?
我尝试使用:
df ['人均GDP日志'] = df ['人均GDP日志'] .apply(lambda x:(((x-b)/(a-b)))
其中我的a是最大值,b是最小值
a = df['Log GDP per capita'].max()
b = df['Log GDP per capita'].min()
df['Log GDP per capita'] = df['Log GDP per capita'].apply(lambda x:((x-b)/(a-b)))
我收到此错误:
TypeError:-:“ NoneType”和“ float”的不受支持的操作数类型
最佳答案
不需要申请
df['Log GDP per capita'] = (df['Log GDP per capita']-b)/(a-b)
您也可以呼叫
sklearn
from sklearn.preprocessing import MinMaxScaler
caler = MinMaxScaler()
scaler.transform(df['Log GDP per capita'])
关于python - 如何标准化数据框的列,而忽略其中的None值?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55561282/