title: Use of Global Variables in Python?
body: <p>I could not reference the original dataframe in the other function, i.e. <code>print_df_in_a_function()</code>. Could anyone please advise the mistake I made here?</p>
  
  <p>It displays <code>None</code> upon calling <code>print_df_in_a_function()</code>.</p>
  
  <pre><code>import numpy as np
  import pandas as pd
  
  df1 = None
  
  def main():
      df1 = pd.DataFrame(np.array([['a', 5, 9],
                                   ['b', 4, 61],
                                   ['c', 24, 9]]),
                                   columns=['name', 'attr1', 'attr2'])
  
      print(df1)
      print_df_in_a_function()
  
  def print_df_in_a_function():
      print(df1)
  
  if __name__ == '__main__':
      main()
  </code></pre>