我想获取一列的最大和最小值的差。
range = DiabeticPatients.diff(DiabeticPatients['Glucose'].max() -
DiabeticPatients['Glucose'].min())
还要使用lambda进行更正。
答案 0 :(得分:2)
使用.ptp()
(从峰到峰)获得最大-最小-最小:
In [1]: import pandas as pd
In [2]: import numpy as np
In [3]: np.random.seed(444)
In [4]: df = pd.DataFrame({"Glucose": np.random.randint(0, 10000, size=100)})
In [5]: df['Glucose'].ptp()
Out[5]: 9947