I'm trying to create an empty global pandas dataframe and then append to it within data processing functions. I'm having trouble figuring out what's going wrong. Here's a minimal example:

```
from datetime import datetime
import pandas as pd

def do_stuff_and_append_df():
    dt = datetime.now()
    row = dict.fromkeys(df.columns.tolist())
    row['datetime'] = dt
    row['pduType'] = 'blah'
    df = df.append(row, ignore_index=True)
    print(df.head())

def main():
    # empty dataframe for appending
    header = ['datetime', 'pduType']
    global df 
    df = pd.DataFrame(columns=header)
    # Main loop
    try:
        while True:
            do_stuff_and_append_df()

    except KeyboardInterrupt:
        print('\nSaving and exiting.')
        df.to_csv('data.csv')

main()

```

I'm getting the error `UnboundLocalError: local variable 'df' referenced before assignment`. Anybody know why I can't call `df` within this function?