Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/316.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在尝试获取pct等级(Python/Pandas/GroupBy/Lambda/pct等级)时,如何处理特定组中的错误_Python_Pandas_Pandas Groupby - Fatal编程技术网

在尝试获取pct等级(Python/Pandas/GroupBy/Lambda/pct等级)时,如何处理特定组中的错误

在尝试获取pct等级(Python/Pandas/GroupBy/Lambda/pct等级)时,如何处理特定组中的错误,python,pandas,pandas-groupby,Python,Pandas,Pandas Groupby,我有一个熊猫数据框架,每个列中都有各种足球统计数据(名称列在ascColumnList中)。我想按多个列(“UTCDate”、“MasterLeagueGUID”、“MasterSeasonGUID”、“TimePeriod”、“SpecificPositionTypeCode”)对数据帧进行分组,然后从0-1获取pctRank,就像SQL Server为列表中的每一列执行计算一样 我有一个辅助函数,用于计算秩并使其正常化: def pctRankAsc(x): r = x.rank(pct=T

我有一个熊猫数据框架,每个列中都有各种足球统计数据(名称列在ascColumnList中)。我想按多个列(“UTCDate”、“MasterLeagueGUID”、“MasterSeasonGUID”、“TimePeriod”、“SpecificPositionTypeCode”)对数据帧进行分组,然后从0-1获取pctRank,就像SQL Server为列表中的每一列执行计算一样

我有一个辅助函数,用于计算秩并使其正常化:

def pctRankAsc(x):
r = x.rank(pct=True, ascending=True)
c = float(r.count())
return (r - 1/c)*(c/(c-1))
然后,我将数据帧分组,然后应用函数:

df = df.apply(lambda x: df.groupby(['UTCDate', 'MasterLeagueGUID', 'MasterSeasonGUID', 'TimePeriod', 'SpecificPositionTypeCode'])[x.name].apply(pctRankAsc).astype(float) if (x.name in ascColList and not(df[x.name].isnull().values.all())) else x)
我的问题是:当特定组的计数为0时(即所有无/NaN等)出现错误。如果我没有正常化,我不会得到这个错误,但是我需要这个步骤

问题:处理这种情况的最佳方式是什么