为什么下面的代码有3次执行?我只希望它执行两次,每个组一次(foo和bar),在bar上有两次执行。你知道吗
import pandas as pd
df = pd.DataFrame({'type' : ['foo', 'bar'], 'cost' : [1, 4]})
def testFunction(currDf):
print currDf
return currDf
grouped_df = df.groupby(['type']).apply(testFunction)
grouped_df
cost type
1 4 bar
cost type
1 4 bar
cost type
0 1 foo
参见docs
熊猫正在弄清楚你是否在改变输入数据。它将决定在计算中使用快速还是慢速路径。你知道吗
相关问题 更多 >
编程相关推荐