#!/usr/bin/env python # coding: utf-8 # # Hoisting dataframes to the module. # # Creating modules from data is different than software # In practice, I really like to tidy up dataframes with specific features cleaned in each notebook. This approach avoids long and difficult to debug notebooks. # In[1]: from pandas import util; df = util.testing.makeDataFrame() # All of the columns in the namespace # In[2]: globals().update(dict(df.items())) # Add dataframe operations to our module # In[3]: import IPython # Hosting attributes. # In[4]: with IPython.utils.capture.capture_output(): globals().update({x: getattr(df, x) for x in dir(df)}) # In[6]: Ø = __name__ == '__main__' if Ø: from deathbeds import __Dataframes_and_modules # In[7]: if Ø: assert isinstance(__Dataframes_and_modules, __import__('types').ModuleType) Ø and __Dataframes_and_modules.sample(2)