0

I have an existing set of data frames that I have imported earlier as show below

import pandas as pd
class command_dictionary(object):
    def __init__(self, file_location ='command_dictionary.xlsx'):
        xls = pd.ExcelFile(file_location)
        self.enum_beacon_mode = xls.parse('enum_beacon_mode', index_col=0, parse_cols=1, na_values=['NA'], has_index_name=True)
        self.enum_boot_source = xls.parse('enum_boot_source', index_col=0, parse_cols=1, na_values=['NA'], has_index_name=True)

Later in the code i want to call one of the initialized data frames.

def validate_command(df_name):
    print df_name #do stuff
    print enum_beacon_mode

How do I take the df_name string argument and use it to call an existing data frame.

Thank you in advance for everyone's help.

andNoob
  • 159
  • 1
  • 10
  • 1
    store the references in a dict or simply pass the name to the function – Padraic Cunningham Sep 01 '15 at 18:36
  • I am unable to pass the full df into the function, the df_name comes as a string input from user. Which part should I store in a dictionary, do you mean the list of data frames? – andNoob Sep 01 '15 at 18:58
  • How are the dataframes created? – Padraic Cunningham Sep 01 '15 at 19:00
  • Thank you for taking the time to look at my question. The Data Frames are created through an import as shown in the 'def __init__'. I do not want to re-import the data frame every time the function is called. I would prefer to keep using the same data frame created in the '__init__'. – andNoob Sep 01 '15 at 19:03
  • Is there a way I can use something like self.df_name – andNoob Sep 01 '15 at 19:04
  • So lots of instances are created? I don't see where the names come from – Padraic Cunningham Sep 01 '15 at 19:05
  • I have about a dozen data frames created in the __init__. Then i would like to use these data frames in a function. The function is called with data frame name as an argument. How do I call an existing data frame with a string argument that was passed into the function. – andNoob Sep 01 '15 at 19:13
  • 1
    get the user to pass the name and use a class dict to store all the df's by name – Padraic Cunningham Sep 01 '15 at 19:17

0 Answers0