-1

I am new into Python, I've been using Matlab for a long time. Most of the features that Python offers outperform those from Matlab, but I still miss some of the features of matlab structures!

Is there a similar way of grouping independent pandas dataframes into a single object? This would be of my convenience since sometimes I have to read data of different locations and I would like to obtain as many independent dataframes as locations, and if possible into a single object.

Thanks!

  • 1
    Please check [How to make good reproducible pandas examples](http://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – jezrael Nov 15 '16 at 08:49
  • Maybe http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html is what you are looking for? – gnebehay Nov 15 '16 at 11:26

1 Answers1

1

I am not sure that I fully understand your question, but this is where I think you are going.

You can use many of the different python data structures to organize pandas dataframes into a single group (List, Dictionary, Tuple). The list is most common, but a dictionary would also work well if you need to call them by name later on rather than position.

**Note: This example uses csv files, these files could be any io that pandas supports (csv, excel, txt, or even a call to a database)

import pandas as pd

files = ['File1.csv', 'File2.csv', 'File3.csv']

frames = [frames.append(pd.read_csv(file)) for file in files]
single_df = pd.concat(frames)

You can use each frame independently by calling it from the list. The following would return the File1.csv dataframe

frames[0]
Waylon Walker
  • 543
  • 3
  • 10