Pandas Panel is deprecated,

2024/11/20 15:41:49

This code snippet is from one of my script which works fine in current panda version (0.23) but Panel is deprecated and will be removed in a future version.

panel = pd.Panel(dict(df1=dataframe1,df2=dataframe2))
diff_output = diff_panel.apply(report_diff, axis=0)

Can someone please help me in translating this which is compatible with the latest version of panda? Its say use .to_xarray or pandas.to_frame()

Answer
import xarray as xr
a = pd.DataFrame({'a':[1,2,3],'b':[4,5,6],'c':[7,8,9]})
b = pd.DataFrame({'a':[11,12,13],'b':[14,15,16],'c':[17,18,19]})
ds = xr.Dataset({1:a, 2:b})
def f(thing):#print(thing)return thing.mean()
>>> q = ds.apply(f)
>>> q
<xarray.Dataset>
Dimensions:  ()
Data variables:1        float64 5.02        float64 15.0
>>> q[1]
<xarray.DataArray 1 ()>
array(5.)
>>> q[1].values
array(5.)
https://en.xdnf.cn/q/118401.html

Related Q&A

Python - Why is this data being written to file incorrectly?

Only the first result is being written to a csv, with one letter of the url per row. This is instead of all urls being written, one per row.What am I not doing right in the last section of this code t…

How does Python interpreter look for types? [duplicate]

This question already has answers here:How does Python interpreter work in dynamic typing?(3 answers)Closed 10 months ago.If I write something like:>>> a = float()how does Python interpreter …

title() method in python writing functions when word like arent

using functiondef make_cap(sentence):return sentence.title()tryining outmake_cap("hello world") Hello World# it workd but when I have world like "arent" and isnt". how to write…

Creating a C++ Qt Gui for a Python logic

I was presented with a Python logic for which I need to create a GUI. I want to use Qt for that purpose and ideally I would like to program it in C++, without using the Qt Creator.What are recommended …

Pythons BaseHTTPServer returns junky responses

I use Pythons BaseHTTPServer and implement the following very simple BaseHTTPRequestHandler:class WorkerHandler(BaseHTTPRequestHandler):def do_GET(self):self.wfile.write({"status" : "rea…

Why is matplotlib failing on import matplotlib.pyplot as plt

I installed matplotlib using conda:conda install matplotlibThe following code failed:#!/usr/bin/env python import matplotlib import matplotlib.pyplot as pltWith this error message:"ImportError: N…

Setting cell color of matplotlib table and save as a figure?

Im following this code a link! to save a table as the image, and I have some feature like check value in a cell then set color for a cell, but I added some code stylemap, it doesnt workimport pandas a…

Errno 111 Connection refused - Python Mininet API hosts client/server no connection?

I am new to Mininet and I am trying to find a way to use a script in python to execute a few tests using Mininet. More precisely I want to build topology and send a few xmlrpc request from one host t…

Finding the Corners of the an array of coordinates

I have a 2D array of Coordinates in Numpy.My goal is to attempt to find the corners (as if it were a square). So the :Top left: smallest x, highest y Top right: largest x, largest y bottom left: smalle…

How to make a dictionary retain its sort order?

def positive(self):total = {}final = {}for word in envir:for i in self.lst:if word in i:if word in total:total[word] += 1else:total[word] = 1final = sorted(total, reverse = True)return totalThis return…