python - Selecting rows in Pandas Panel -


is there way select rows across pandas panel?

for instance in following example rows job == "b" across dataframes? in regular dataframe know using

df1[df1["job"] == "a"]

but i'm unsure how in pandas panels without loops.

df1 = pd.dataframe({"job":["a", "b", "c", "d"],"date":["datea1", "dateb1", "datec1", "dated1"]}) df2 = pd.dataframe({"job":["b", "c", "d", "e"],"date":[ "dateb2", "datec2", "dated2", "datee2"]}) p = pd.panel({"df1":df1, "df2":df2}) 

my question might duplicate of one

boolean masking in panels

it might more convenient (at least me :-)) work 2d df rather 3d panel.

df1 = pd.dataframe({"job":["a", "b", "c", "d"],"date":["datea1", "dateb1", "datec1", "dated1"]}) df2 = pd.dataframe({"job":["b", "c", "d", "e"],"date":[ "dateb2", "datec2", "dated2", "datee2"]}) p = pd.panel({"df1":df1, "df2":df2})  frame = p.to_frame()  out[12]:                  df1     df2 major minor                 0     date   datea1  dateb2       job               b 1     date   dateb1  datec2       job         b       c 2     date   datec1  dated2       job         c       d 3     date   dated1  datee2       job         d       e   res = frame.unstack('minor').stack(level=0)  out[13]:  minor        date job major                 0     df1  datea1         df2  dateb2   b 1     df1  dateb1   b       df2  datec2   c 2     df1  datec1   c       df2  dated2   d 3     df1  dated1   d       df2  datee2   e   res.loc[res['job'] == 'b', :]  out[14]:  minor        date job major                 0     df2  dateb2   b 1     df1  dateb1   b 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -