小编ala*_*ant的帖子

在 pandas 1.4 中使用 pd.concat 而不是 df.append

我在代码中使用df.append()在数据帧列之间附加百分比变化。由于df.append()在 pandas 1.4 中被折旧,我尝试使用pd.concat但无法复制输出。

这就是我现在所拥有的:

import numpy as np
import pandas as pd

df = pd.DataFrame({"A": ["foo", "foo", "foo", "foo", "foo",
                         "bar", "bar", "bar", "bar"],
                   "B": ["one", "one", "one", "two", "two",
                         "one", "one", "two", "two"],
                   "C": ["small", "large", "large", "small",
                         "small", "large", "small", "small",
                         "large"],
                   "D": [1, 2, 2, 3, 3, 4, 5, 6, 7],
                   "E": [2, 4, 5, 5, 6, 6, 8, 9, 9]})

table = pd.pivot_table(df, values='D', index=['A', 'B'],
                    columns=['C'], aggfunc=np.sum, fill_value=0, …
Run Code Online (Sandbox Code Playgroud)

python dataframe pandas

5
推荐指数
1
解决办法
7669
查看次数

标签 统计

dataframe ×1

pandas ×1

python ×1