FutureWarning: Panel is deprecated and will be removed in a future version. The recommended way to represent these types of 3-dimensional data are with a MultiIndex on a DataFrame, via the Panel.to_frame() method.
I am getting the above error whenever i ran this code!
difference = pd.Panel(dict(df1=df1,df2=df2))
Can anyone please tell me the alternative way for usage of Panel with the above line of code.
Edit-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)
Here df1 and df2 contains both categorical and numerical data. Just comparing the two dataframes here to get the differences between the two.
As stated in the docs, the recommended replacements for a Pandas Panel are using a multindex, or the xarray
library.
For your specific use case, this somewhat hacky code gets you the same result:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With