我正在使用我已经在我的工作中使用了很长时间的聚合函数.这个想法是,如果系列传递给函数的长度为1(即该组只有一个观察值),则返回该观察值.如果传递的系列的长度大于1,则在列表中返回观察结果.
这对某些人来说可能看起来很奇怪,但这不是X,Y问题,我有充分的理由想要这样做与这个问题无关.
这是我一直在使用的功能:
def MakeList(x):
""" This function is used to aggregate data that needs to be kept distinc within multi day
observations for later use and transformation. It makes a list of the data and if the list is of length 1
then there is only one line/day observation in that group so the single element of the list is returned.
If the list is longer than one then there are multiple line/day observations and the list itself is …Run Code Online (Sandbox Code Playgroud) pandas.crosstab和Pandas数据透视表似乎都提供了完全相同的功能.有什么不同吗?