Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

concatenate dataframe with dataframe from list

I want to concatenate a dataframe (df) with another dataframe that is stored in a list of dataframes.

dflist = [df1, df2, df3]

What I want is a dataframe like below

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

new_dflist = [df+df1, df+df2, df+df3]

new_dflist=[]
for n in dflist:
    new_dflist.append(pd.concat(df, dflist[n]))

but I get the error,
TypeError: list indices must be integers or slices, not DataFrame

I also tried with enumerate but I get the error,
TypeError: list indices must be integers or slices, not tuple

>Solution :

Try this:

dflist = [df1, df2, df3]
new_dflist=[]
for n in dflist:
    new_dflist.append(pd.concat(df, n))

n is a dataframe and you are trying to put it in list index

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading