这是我的简单代码
def custom_func(x):
for el in x.index:
print(el)
return None
df = pd.DataFrame({'A':['F','F','F','K','K'], 'B':[54,87,35,25,82],
'C':[56,78,0,14,13]})
mask = df.groupby(['A'])['B'].transform(custom_func)
它会生成以下错误消息:
Traceback (most recent call last):
File "C:/Users/temp3.py", line 59, in <module>
consecutive_check()
File "C:/Users/temp3.py", line 56, in consecutive_check
mask = df.groupby(['A'])['B'].transform(custom_func)
File "C:\Anaconda3\lib\site-packages\pandas\core\groupby.py", line 2763, in transform
result[indexer] = res
TypeError: int() argument must be a string, a bytes-like object or a number, not 'NoneType'
有什么问题,为什么我会收到此错误消息。
答案 0 :(得分:1)
也许是因为无论输入如何,您的函数始终返回None
。你能否提供一个更完整的描述你期望的最终结果?