0

I'm getting that error eventhough the name of my function is different from that of my variable inside the function.

import pandas as pd

df = pd.read_csv('file.csv', usecols=('Date','Col2','Col3'))

def foo():
    df['Date'] = pd.to_datetime(df.Date)
    df = df.dropna()
    return df
print(foo())

Here's the error that I'm getting:

df['Date'] = pd.to_datetime(df.Date)
UnboundLocalError: local variable 'df' referenced before assignment

What should i do to resolve the issue?

ssmm
  • 149
  • 2
  • 15

0 Answers0