to update: use the @azro code and modify only the indexes of the for. it doesn't mark me error with your answers, the code works fine, however I still don't get the expected result, I put my full code.
arch is dataframe
channels=['ch1','ch1']
targets=['op1','op2']
l=[]
m = []
n = []
for ch in channels:
for tar in targets:
for j in range(1,22):
df=arch[(arch.Año.isin(año)) & (arch['Channel'] == ch) & (rcha['Week'] == j)]
l.append(df[['time',tar]].set_index('time').rename(columns={'time' : 'time' + str(j)}))
m.append(l)
n.append(m)
a = []
for i in range(len(n)):
for j in range(len(m)):
for k in range(len(l)):
a.append(n[i][j][k])
a = pd.concat(a, axis=1).reset_index()
by printing "a" I get
time | op1 | op1 |...| op2 | op2 |..| op1 | op1 | op2 |..| op2
1 | 0.2 | 0.1 | | 0.2 | 0.1 |..| 0.1 | 0.1 | 0.2 |..| 0.8
2 | 0.3 | 0.4 | | 0.1 | 0.3 |..| 0.2 | 0.7 | 0.9 |..| 0.3
3 | 0.7 | 0.8 | | 0.9 | 0.11|..| 0.4 | 0.8 | 0.7 |..| 0.8
I have it like this, because I have two elements in "channels" and two elements in "targets" and I need to print a table for "ch1 with op1", "ch1 with op2", "ch2 with op1", "ch2 with op2".
for ch1
time | op1 | op1 |..
1 | 0.2 | 0.1 |..
2 | 0.3 | 0.4 |..
3 | 0.7 | 0.8 |
time | op2 | op2 |..
1 | 0.2 | 0.1 |..
2 | 0.1 | 0.3 |..
3 | 0.9 | 0.11|..
for ch2
time | op1 | op1 | ..
1 | 0.1 | 0.1 | ..
2 | 0.2 | 0.7 | ..
3 | 0.4 | 0.8 | ..
time | op2 |..| op2
1 | 0.2 |..| 0.8
2 | 0.9 |..| 0.3
3 | 0.7 |..| 0.8
pd.concatexpects to concatenate multiple things, but you passed it a single DataFrame. Perhapsa = pd.concat(np.flatten(n), axis=1).reset_index()?