title: Variable scoping and sharing "global" reference dataframes
body: <p>Old-school programmer brand new to Python &amp; pandas. The mutable datatypes are super cool, but they make it hard to intuit how to set up "global" reference data structures.</p>
  
  <p>I have a bunch of reference data (currently tens of MB, but it will be hundreds of MB in final version). Quite a few different classes and scripts need to reference the same data. This is historical reference data. It changes very infrequently, through batch update from .CSVs.</p>
  
  <p>It would be very inefficient to load this data into memory several times over. I want to load the data once the first time that it's used, then reference the same copy each time it's needed. Forgive the old-school references (I learned to program in the 1970s), but the "old way" of doing this would be to declare a GLOBAL pointer variable that points to a single copy of the several pandas dataframes that contain the reference data. The dataframes would be loaded from .CSV the FIRST time they were referenced, then all the different classes and scripts would just use that pointer variable to find the already memory-resident single copy of the data.</p>
  
  <p>What I can't figure out is the best way to do this in Python/pandas so that all the different modules access a single copy (that doesn't get unnecessarily replicated).</p>
  
  <p>I thought about a container class with methods to access a single copy of the data. The problem there is that pandas.DataFrame already offers such great features that I want all the other modules to have access to all the built-in methods of DataFrame. I see how I could make the "reference dataframe" an attribute of a container class, but I believe that would result in each different piece of code that retrieves that attribute getting a new COPY of the DataFrame, which could be 100MB+. All the different pieces of code referencing the same DataFrame don't NEED to be "protected from stepping on one another" because the data is read-only. But pandas doesn't know that and I fear it will copy the data for each independent class or script that asks for a dataframe object from the container class attribute.</p>
  
  <p>I feel like what's needed is to somehow tell pandas "hey, this huge dataframe is static/readonly reference data, so don't copy it every time a different module asks for its own object handle to it, ok?"  Is there a way to do that?</p>
  
  <p>Thanks!</p>
  
  <pre><code>from MyLib.refdata import RefData
  
  rd = RefData()   # Create instance of container class that has my reference data
  
  df = rd.OilPrices # returns 100MB pandas DataFrame object that was loaded
                             # by my container class. My fear is that pandas will make a
                             # copy of that giant dataframe so that if my code overwrites
                             # some of the data, it won't affect other users of the class who
                             # probably got their own copies. I don't want that. I want ONE
                             # copy.
  </code></pre>