读取数据的归一化处理

import numpy as np
import pandas as pd;
f = open('流量异常指标集数据.csv')
coman = pd.read_csv(f)
coman.replace([np.inf, -np.inf], np.nan,inplace=True)
coman = coman.fillna(0)
def regularit(df):
    newDataFrame = pd.DataFrame(index=df.index)
    columns = df.columns.tolist()
    for c in columns:
        if (c == 'tableName'):
            newDataFrame[c] = df[c].tolist()
        else:
            d = df[c]
            MAX = d.max()
            MIN = d.min()
            newDataFrame[c] = ((d - MIN) / (MAX - MIN)).tolist()
    return newDataFrame
data = regularit(coman)
data.to_csv('a.csv', sep=',', header=True, index=False)       #header头部   index行号

你可能感兴趣的:(自学记录)