General Issue
I have an arbitrary list of pandas.DataFrame's (let's use 2 to keep the example clear), and I want to concat them on an Index that:
- is neither the
innernor theouterjoin of the existingDataFrames - is a different, separate
Index, but only has dates within all theDataFrame's
For example, take the following 2 DataFrame's (note the difference in Index shapes):
In [01]: d1 = pandas.DataFrame( numpy.random.randn(15, 4), columns = ['a', 'b', 'c', 'd'], index = pandas.DatetimeIndex(start = '01/01/2001', freq = 'b', periods = 15) ) In [02]: d2 = pandas.DataFrame( numpy.random.randn(17, 4), columns = ['e', 'f', 'g', 'h'], index = pandas.DatetimeIndex(start = '01/05/2001', freq = 'b', periods = 17) ) I would like to join these two DataFrame's on an intersecting Index, such my_index, constructed here:
In [03]: ind = range(0, 10, 2) In [04]: my_index = d2.index[ind].copy() So the following result should have the same results as:
In [05]: d1.loc[my_index, :].join(d2.loc[my_index, :] ) Out[65]: a b c d e f \ 2001-01-05 1.702556 -0.885554 0.766257 -0.731700 -1.071232 1.806680 2001-01-09 -0.968689 -0.700311 1.024988 -0.705764 0.804285 -0.337177 2001-01-11 1.249893 -0.613356 1.975736 -0.093838 0.428004 0.634204 2001-01-15 0.430000 0.502100 0.194092 0.588685 -0.507332 1.404635 2001-01-17 1.005721 0.604771 -2.296667 0.157201 1.583537 1.359332 g h 2001-01-05 -1.183528 1.260880 2001-01-09 0.352487 0.700853 2001-01-11 1.060694 0.040667 2001-01-15 -0.044510 0.565152 2001-01-17 -0.731624 -0.331027 Personal Considerations
Because this is for a larger application, and I will have an arbitrary number of DataFrame's I'd like to:
- Use existing
pandasfunctionality instead of building my own hack, i.e.reduce( map ( ) )etc. - Return views of the intersection of the
DataFrame's instead of creating copies of theDataFrame's