Inserting data into Multiindexed DataFrames using .xs()

11 views
Skip to first unread message

Paul Symonds

unread,
Jul 15, 2016, 8:32:12 AM7/15/16
to PyData
After several days of pondering and having no responses on StackOverflow, I thought it wise to raise a discussion here.

I have been trying to find an efficient way of inserting data into a MultiIndexed DataFrame.   A MultiIndexed DataFrame can essentially show the time series data partitioned at various levels.   Using the MultiIndex in this way allows data to be shifted through time and for calculations to be run across the frame.  What I would like to be able to do is to add new colums at any level such that I could use assign() or an apply() to derive new columns from existing on the MultiIndexed frame.  

In order to do this I would need to iterate over each level and use .xs() to filter the DataFrame and from here it seems that one possible solution would be to filter then apply a function to create a new column value at a particular level.  Does this sound feasible and is it currently possible?


Paul
Reply all
Reply to author
Forward
0 new messages