更改系列列名后应用函数并返回多个数据框

2024-09-26 22:54:38 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个函数,返回多个系列,并希望重命名系列名称。你知道吗

 def myfunction(MyDataFrame, UniqueID, Var1, Var2):
     RunningSumA = MyDataFrame.groupby([UniqueID])[Var1].cumsum().reset_index()
     RunningSumB = MyDataFrame.groupby([UniqueID])[Var2].cumsum().reset_index()

     return pd.Series([RunningSumA, RunningSumB])


 Result = myfunction(MyDataFrame, UniqueID, Var1, Var2)

当我查看结果系列的前几行时,结果如下:

Result[0].head()

  index    0
0  216646  0
1  216647  0
2  216648  0
3  216649  0
4  216650  0

我想将index0重命名为函数中有意义的内容。我试着重新命名这些列,但无法重新命名。我该怎么做?你知道吗


Tags: 函数indexresult重命名resetgroupbymyfunction重新命名

热门问题