我在名为items的DataFrame中有这样的数据:
Yr Mo Count
1 2008 2 14
2 2008 3 37
3 2008 4 23
4 2008 5 22
5 2008 6 32
6 2008 7 45
7 2008 8 33
8 2008 9 24
9 2008 10 70
10 2008 11 48
11 2008 12 60
12 2009 1 63
13 2009 2 64
14 2009 3 60
15 2009 4 63
16 2009 5 41
17 2009 6 44
18 2009 7 42
19 2009 8 47
20 2009 9 57
21 2009 10 62
22 2009 11 47
23 2009 12 50
我正在尝试使用groupby.transform应用一个函数,并且该函数应用于' Yr'柱。 我试图应用的功能如下:
def normal (list):
for item in list:
mn = min(list)
mx = max(list)
(item-mn)/(mx-mn)
我尝试用于groupby.transform的代码行是这样的:
import pandas as pd
appts2['normal'] = appts2.groupby('Yr')['Count'].transform(normal)
以下是我得到的追溯:
Traceback (most recent call last):
File "<ipython-input-49-6f01ec40e613>", line 1, in <module>
appts2['Normal'] = appts2.groupby('Yr')['Count'].transform(normal)
File "file location", line 2845, in transform
result[indexer] = res
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
答案 0 :(得分:0)
Paul Panzer感谢您的帮助,
我将功能更改为此功能,现在它正常工作:
def normal (list):
mn = min(list)
mx = max(list)
result=[]
for item in list:
result.append((item-mn)/(mx-mn))
result = pd.Series(result)
return result