pandas归一化与反归一化操作实现
苍穹之跃 人气:0import numpy as np import pandas as pd import matplotlib.pylab as plt if __name__ == '__main__': """ 原数据 """ df = pd.DataFrame({'A': [10, 20, 30], 'B': [1, 2, 6]}) # 图表 plt.plot(df) plt.show() """ 归一化 """ # 最小值 minimum = df.min() # 最大值 maximum = df.max() df_zero_one = (df - minimum) / (maximum - minimum) # 图表 plt.plot(df_zero_one) plt.show() """ 反归一化 """ df_un_zero_one = (maximum - minimum) * df_zero_one + minimum # 图表 plt.plot(df_un_zero_one) plt.show()
import numpy as np import pandas as pd import matplotlib.pylab as plt if __name__ == '__main__': """ 原数据 """ df = pd.DataFrame({'A': [10, 20, 30], 'B': [1, 2, 6]}) # 图表 subplot_1 = plt.subplot(2, 2, 1) subplot_1.plot(df) """ 归一化 """ # 最小值 minimum = df.min() # 最大值 maximum = df.max() df_zero_one = (df - minimum) / (maximum - minimum) # 图表 subplot_2 = plt.subplot(2, 2, 2) subplot_2.plot(df_zero_one) """ 反归一化 """ df_un_zero_one = (maximum - minimum) * df_zero_one + minimum # 图表 subplot_3 = plt.subplot(2, 2, 3) subplot_3.plot(df_un_zero_one) plt.show()
加载全部内容