I am having trouble adding several dataframes in a list of dataframes. My goal is to add dataframes from a list of dataframes based on the criteria from another list.
Example: Suppose we have a list of 10 Dataframes, DfList and another list called OrderList.
Suppose OrderList = [3, 2, 1, 4].
Then I would like to obtain a new list of 4 Dataframes in the form [DfList(0) + DfList(1) + DfList(2), DfList(3) + DfList(4), DfList(5), DfList(6) + DfList(7) + DfList(8) + DfList(9)]
I have tried a few ways to do this creating functions using DataFrame.add. Initially, my hope was that I could use the form sum(DfList(0), DfList(1), DfList(2)) to do this but quickly learned that sum() doesn't seem to be supported with DataFrames.
I was hoping to use something like sum(DfList[0:2]) and making OrderList cumulative so I could just use sum(DfList[OrderList[i]:OrderList[i+1]]) but keep getting unsupported operand type errors.
Is there an easy way to do this that I am not considering or is there a different approach entirely that you would suggest?
EDIT: The output I am looking for is another list of DataFrames containing four summed DataFrames based on OrderList (across all columns.) Three DataFrames added together for the first, two for the second, one for the third, and four for the fourth.
OrderListhave in this?OrderList=[3, 2, ...]to sum the first three elements, then the next two, etc. Next, you are asking how to add different numbers of DataFrames. The second question the guy below already answered :) For the first, you should start with something simpler, like summing[1, 2, 3, 4, 5]with order[2, 3]to give[3, 12]. This way you don't have to worry about data structures whatsoever, just the language. Sorry I don't have the time to come with an answer for you, but it shouldn't be hard, just do your best :)