1

I have two lists, each one with the same number of dataframes that I imported from csv files.

So "dataframes" has 12 dataframes and "Dataframes potential" has also 12 Dataframes.

They have the same number of rows and I would like to concatenate them (pair of each one).

dataframes

    [                       Name  people  ...  Tcs_sys_sup_C  Tcs_sys_re_C
 DATE                                 ...                             
 2011-01-01 00:00:00  B10540    42.0  ...            0.0           0.0
 2011-01-01 01:00:00  B10540    42.0  ...            0.0           0.0
 2011-01-01 02:00:00  B10540    42.0  ...            0.0           0.0
 2011-01-01 03:00:00  B10540    42.0  ...            0.0           0.0
 2011-01-01 04:00:00  B10540    42.0  ...            0.0           0.0
 ...                     ...     ...  ...            ...           ...
 2011-12-31 19:00:00  B10540    41.0  ...            0.0           0.0
 2011-12-31 20:00:00  B10540    41.0  ...            0.0           0.0
 2011-12-31 21:00:00  B10540    42.0  ...            0.0           0.0
 2011-12-31 22:00:00  B10540    42.0  ...            0.0           0.0
 2011-12-31 23:00:00  B10540    42.0  ...            0.0           0.0
 
 [8760 rows x 136 columns],
                        Name  people  ...  Tcs_sys_sup_C  Tcs_sys_re_C
 DATE                                 ...                             
 2011-01-01 00:00:00  B10549     1.0  ...            0.0           0.0
 2011-01-01 01:00:00  B10549     1.0  ...            0.0           0.0
 2011-01-01 02:00:00  B10549     1.0  ...            0.0           0.0
 2011-01-01 03:00:00  B10549     1.0  ...            0.0           0.0
 2011-01-01 04:00:00  B10549     1.0  ...            0.0           0.0
 ...                     ...     ...  ...            ...           ...
 2011-12-31 19:00:00  B10549     1.0  ...            0.0           0.0
 2011-12-31 20:00:00  B10549     1.0  ...            0.0           0.0
 2011-12-31 21:00:00  B10549     1.0  ...            0.0           0.0
 2011-12-31 22:00:00  B10549     1.0  ...            0.0           0.0
 2011-12-31 23:00:00  B10549     1.0  ...            0.0           0.0
 
 [8760 rows x 136 columns],.....

and Dataframes potential

    [                     SC_FP_walls_south_Q_kWh  ...  T_SC_re_C
 Date                                          ...           
 2011-01-01 00:00:00                      0.0  ...        NaN
 2011-01-01 01:00:00                      0.0  ...        NaN
 2011-01-01 02:00:00                      0.0  ...        NaN
 2011-01-01 03:00:00                      0.0  ...        NaN
 2011-01-01 04:00:00                      0.0  ...        NaN
 ...                                      ...  ...        ...
 2011-12-31 19:00:00                      0.0  ...        NaN
 2011-12-31 20:00:00                      0.0  ...        NaN
 2011-12-31 21:00:00                      0.0  ...        NaN
 2011-12-31 22:00:00                      0.0  ...        NaN
 2011-12-31 23:00:00                      0.0  ...        NaN
 
 [8760 rows x 18 columns],
                      SC_FP_walls_south_Q_kWh  ...  T_SC_re_C
 Date                                          ...           
 2011-01-01 00:00:00                      0.0  ...        NaN
 2011-01-01 01:00:00                      0.0  ...        NaN
 2011-01-01 02:00:00                      0.0  ...        NaN
 2011-01-01 03:00:00                      0.0  ...        NaN
 2011-01-01 04:00:00                      0.0  ...        NaN
 ...                                      ...  ...        ...
 2011-12-31 19:00:00                      0.0  ...        NaN
 2011-12-31 20:00:00                      0.0  ...        NaN
 2011-12-31 21:00:00                      0.0  ...        NaN
 2011-12-31 22:00:00                      0.0  ...        NaN
 2011-12-31 23:00:00                      0.0  ...        NaN
 
 [8760 rows x 18 columns],....

I tried a very simple

frames=[dataframes_potencial_process,dataframes] 
pd.concat(frames)
TypeError: cannot concatenate object of type '<class 'list'>'; only Series and DataFrame objs are valid

Thank you

1
  • Suppose you have: dfs = [df1, df2, df3], and dfs_potential = [dfp1, dfp2, dfp3]. Its hard to tell from your question whether you want final = df1+df2+df3+dfp1+dfp2+dfp3 (case 1) OR final = [df1+dfp1, df2+dfp2, df3+dfp3] (case 2). If you just want to concat everything (case 1), use final= pd.concat(dfs + dfs_potential, axis =1). For case 2, use [pd.concat([dfs[i], dfs_potential[i]], axis=1) for i in len(dfs)] Commented Apr 14, 2021 at 16:54

2 Answers 2

1

As you stated in the question, you want to concatenate them (pair of each one). You can use zip and pd.concat with axis=1:

pairs = [pd.concat(d, axis=1) for d in zip(dataframes_potencial_process, dataframes)]

# print the pairs:
print(*pairs, sep="\n\n")
Sign up to request clarification or add additional context in comments.

Comments

1

Try with concat() method:

dataframes_potencial_process=pd.concat(dataframes_potencial_process,ignore_index=True)
dataframes=pd.concat(dataframes,ignore_index=True)

Finally again use concat() method:

resultdf=pd.concat((dataframes_potencial_process,dataframes),ignore_index=True,axis=1)

Now if you print resultdf you will get your desired output

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.