I'm trying to create a pandas DataFrame to collect everything I have but I'm having difficulty combining numpy arrays in a list to create a single array.
Suppose I have the following data:
df0 = pd.DataFrame([[1,2],[2,2],[3,1],[4,4],[5,4]], columns = ['A','B'])
collect = []
for i in range(5):
collect.append(df0.mean())
collect.append((i**2+2))
Here, I obviously made it simpler by looping over the same dataframe 5 times but in my actual data, every iteration goes through different columns in the dataframe. Anyway, I want an end result of:
A B i
3.0 2.6 2
3.0 2.6 3
3.0 2.6 6
3.0 2.6 11
3.0 2.6 18
but I can't create a 5x3 matrix because len(collect) is 10. I think I'm not using .append in the right way in the for-loop. How do I create an array such that len(collect) is either 5 or 15? I'm thinking if it's of length 5, we can simply transpose collect or of it's of length 15, we can reshape it.
Edit: I changed the third column a bit so that one can see that it's different from a simple index column.