{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Hoisting dataframes to the module.\n", "\n", "Creating modules from data is different than software\n", "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." ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from pandas import util; df = util.testing.makeDataFrame()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "All of the columns in the namespace" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "globals().update(dict(df.items()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add dataframe operations to our module" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import IPython" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Hosting attributes." ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "with IPython.utils.capture.capture_output(): globals().update({x: getattr(df, x) for x in dir(df)})\n" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "Ø = __name__ == '__main__'\n", "if Ø: from deathbeds import __Dataframes_and_modules" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | A | \n", "B | \n", "C | \n", "D | \n", "
---|---|---|---|---|
QyXyHT1cgE | \n", "2.395613 | \n", "0.189797 | \n", "0.247524 | \n", "0.756322 | \n", "
CpKDTadz2K | \n", "-0.667076 | \n", "-1.609436 | \n", "1.048942 | \n", "-0.031083 | \n", "