Skip to content
Advertisement

How to merge a list composed of many variables and a DataFrame in a single Python Dataframe?

I’ve created a list named “list_data” which contains variables from many files. I also have a dataframe named “observation_data”. I’m trying to merge these 2 files with the key “time”, but nothing to do, all my tentatives fail. Here is my code and my results

JavaScript

And I’ve tried:

JavaScript

Which return an element of 0 row and 35 columns

I’ve also tried:

JavaScript

and no success too:

TypeError: merge() missing 1 required positional argument: ‘right’

Before the merge and concact tentatives, my list_data and observation_data are not empty here is an example:

list_data : (list)

JavaScript

observation_data : (pandas.core.frame.DataFrame)

JavaScript

I’ve also tried to convert my list in a dataframe:

JavaScript

but I get something like that which is not good at all:

JavaScript

What could I do to merge this list and the dataframe together?

Advertisement

Answer

If list_data is a list of pandas data frames, you can use pd.concat to concatenate them all into a single data frame. Use axis=0 to concatenate along the row axis, or axis=1 to concatenate along the column axis.

JavaScript

This guide may also be useful to you.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement