当我将一个函数应用于 groupby 对象的多个列时,Pandas 会抛出一个未来警告。它建议使用列表作为索引而不是元组。怎么办呢?
>>> df = pd.DataFrame([[1,2,3],[4,5,6],[7,8,9]])
>>> df.groupby([0,1])[1,2].apply(sum)
<stdin>:1: FutureWarning: Indexing with multiple keys (implicitly converted to a tuple of keys) will be deprecated, use a list instead.
1 2
0 1
1 2 2 3
4 5 5 6
7 8 8 9
Run Code Online (Sandbox Code Playgroud)