title: import python file into jupyter notebook
body: <p>I have a python file bucket.py.  I'm trying to import it in to a jupyter notebook using the code below.  I'm then trying to use one of the functions in it "exp1" to explore a dataframe.  I'm getting the error below.  Can someone please tell me how to import a file from a directory so I can use the functions in it, in my jupyter notebook?</p>
  
  <h1>code:</h1>
  
  <pre><code>import importlib.util
  spec = importlib.util.spec_from_file_location("module.name", '/Users/stuff/bucket/bucket.py')
  foo = importlib.util.module_from_spec(spec)
  
  
  foo.exp1(df)
  </code></pre>
  
  <p>error:</p>
  
  <pre><code>---------------------------------------------------------------------------
  AttributeError                            Traceback (most recent call last)
  &lt;ipython-input-9-e1cc80f06e24&gt; in &lt;module&gt;
  ----&gt; 1 foo.exp1(harborsideoakland_df)
  
  AttributeError: module 'module.name' has no attribute 'exp1'
  </code></pre>
  
  <p>bucket.py file:</p>
  
  <pre><code># import libraries
  
  import numpy as np
  import pandas as pd
  from time import time
  import scipy.stats as stats
  
  from IPython.display import display # Allows the use of display() for DataFrames
  
  # # Pretty display for notebooks
  # %matplotlib inline
  
  ###########################################
  # Suppress matplotlib user warnings
  # Necessary for newer version of matplotlib
  import warnings
  warnings.filterwarnings("ignore", category = UserWarning, module = "matplotlib")
  #
  # Display inline matplotlib plots with IPython
  from IPython import get_ipython
  get_ipython().run_line_magic('matplotlib', 'inline')
  ###########################################
  
  import matplotlib.pyplot as plt
  import matplotlib.cm as cm
  
  import warnings
  warnings.filterwarnings('ignore')
  
  import seaborn as sns
  
  from sklearn.cluster import KMeans
  from sklearn.metrics import silhouette_score
  from sklearn.preprocessing import MinMaxScaler
  from sklearn.decomposition import PCA
  
  
  
  
  
  
  
  
  ### HELPER FUNCTIONS:
  
  # Initial Exploration
  
  
  
  def exp1(df):
  
      with pd.option_context('display.max_rows', None, 'display.max_columns', None):
          # shape of data
  
          print('rows and columns: {}'.format(df.shape))
  
          # head data
  
          # display(df.head())
          print('')
          # data types and columns in data
          print('data types and columns in data:')
          print('')
          #display(df.info())
          print(df.info())
          print('')
          # unique values in each column
          print('unique values in each column:')
          #display(df.nunique())
          print(df.nunique())
          print('')
          # percentage duplicates
          print('percentage duplicates : {}'.format(1-(float(df.drop_duplicates().shape[0]))/df.shape[0]))
          print('')
          ## Percentage of column with missing values
          print('Percentage of column with missing values:')
          print('')
          missingdf=df.apply(lambda x: float(sum(x.isnull()))/len(x))
  
          #display(missingdf.head(n=missingdf.shape[0]))
          print(missingdf.head(n=missingdf.shape[0]))
          print('')
          print('Data snapshot:')
          print('')
  
          print(df[:5])
  </code></pre>