已弃用 Pandas.Panel 的替代方案是什么
What is the alternative for the deprecated Pandas.Panel
未来警告:
面板已弃用,将在未来版本中删除。
表示这些类型的 3 维数据的推荐方法是通过 Panel.to_frame() 方法在 DataFrame 上使用 MultiIndex。
每当我 运行 此代码时,我都会收到上述错误!
difference = pd.Panel(dict(df1=df1,df2=df2))
谁能告诉我使用上述代码行的 Panel 的替代方法。
编辑-1:-
def report_diff(x):
return x[0] if x[0] == x[1] else '{} ---> {}'.format(*x)
difference = pd.Panel(dict(df1=df1,df2=df2))
res = difference.apply(report_diff, axis=0)
这里 df1 和 df2 包含分类数据和数值数据。
只是比较这里的两个数据帧来了解两者之间的差异。
与 stated in the docs 一样,Pandas 面板的推荐替代品是使用多索引或 xarray
库。
对于您的特定用例,这段有点老套的代码会得到相同的结果:
a = df1.values.reshape(df1.shape[0] * df1.shape[1])
b = df2.values.reshape(df2.shape[0] * df2.shape[1])
res = np.array([v if v == b[idx] else str(v) + '--->' + str(b[idx]) for idx, v in enumerate(a)]).reshape(
df1.shape[0], df1.shape[1])
res = pd.DataFrame(res, columns=df1.columns)
未来警告: 面板已弃用,将在未来版本中删除。 表示这些类型的 3 维数据的推荐方法是通过 Panel.to_frame() 方法在 DataFrame 上使用 MultiIndex。
每当我 运行 此代码时,我都会收到上述错误!
difference = pd.Panel(dict(df1=df1,df2=df2))
谁能告诉我使用上述代码行的 Panel 的替代方法。
编辑-1:-
def report_diff(x):
return x[0] if x[0] == x[1] else '{} ---> {}'.format(*x)
difference = pd.Panel(dict(df1=df1,df2=df2))
res = difference.apply(report_diff, axis=0)
这里 df1 和 df2 包含分类数据和数值数据。 只是比较这里的两个数据帧来了解两者之间的差异。
与 stated in the docs 一样,Pandas 面板的推荐替代品是使用多索引或 xarray
库。
对于您的特定用例,这段有点老套的代码会得到相同的结果:
a = df1.values.reshape(df1.shape[0] * df1.shape[1])
b = df2.values.reshape(df2.shape[0] * df2.shape[1])
res = np.array([v if v == b[idx] else str(v) + '--->' + str(b[idx]) for idx, v in enumerate(a)]).reshape(
df1.shape[0], df1.shape[1])
res = pd.DataFrame(res, columns=df1.columns)