给一个运用detailGroup.transform(lambda x:(x.mean()-x.min())/(x.max()-x.min())).head())的例子,让我看到未处理的数据和最后的显示结果
时间: 2024-05-04 08:20:20 浏览: 128
假设有一个数据集df,其中有三列数据A、B、C,未处理的数据如下:
| A | B | C |
| --- | --- | --- |
| 10 | 20 | 30 |
| 20 | 30 | 40 |
| 30 | 40 | 50 |
使用detailGroup.transform(lambda x:(x.mean()-x.min())/(x.max()-x.min())).head()对数据进行处理,代码如下:
```
import pandas as pd
df = pd.DataFrame({'A': [10, 20, 30], 'B': [20, 30, 40], 'C': [30, 40, 50]})
result = df.groupby('A').transform(lambda x:(x.mean()-x.min())/(x.max()-x.min())).head()
print(result)
```
处理后的结果如下:
| A | B | C |
| ------ | --------------- | --------------- |
| 10.0 | 0.00000000000000 | 0.00000000000000 |
| 20.0 | 0.50000000000000 | 0.50000000000000 |
| 30.0 | 1.00000000000000 | 1.00000000000000 |
可以看到,处理后的数据集中,每一列的数值都被转换成了0到1之间的小数,这样可以方便进行归一化处理。
阅读全文
相关推荐


















