I was teaching a workshop today, and 5 people in my class had the error mentioned above when they used the line import pandas as pd
.
Here's the traceback:
I've never heard of this variable before, and there was no mention of this particular issue with pandas in this particular context.
Some background:
Any idea what the issue may have been?
The Python "UnboundLocalError: Local variable referenced before assignment" occurs when we reference a local variable before assigning a value to it in a function. To solve the error, mark the variable as global in the function definition, e.g. global my_var .
The UnboundLocalError: local variable referenced before assignment error is raised when you try to assign a value to a local variable before it has been declared. You can solve this error by ensuring that a local variable is declared before you assign it a value.
I had the same issue. I uninstalled Pandas and reinstalled with version 0.25.1 which seemed to fix the issue. Must have been a bug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With