-1

AttributeError: partially initialized module 'pandas' has no attribute 'read_csv' (most likely due to a circular import)

I get the above error when I run the below code

import time
import os
import pandas

while True :
    
    if os.path.exists("files/temps_today.csv") :
        data= pandas.read_csv("files/temps_today.csv")
        print(data.mean())

    else : 
        print("File does not exist.")

    time.sleep(10)
Ynjxsjmh
  • 28,441
  • 6
  • 34
  • 52
Mansi
  • 1
  • 2
  • You appear to have named a file `pandas.py` - might be this script, might be a different one. It's being picked up by the `import pandas` instead of the actual module. You need to rename it, and delete any `pandas.pyc` or similar file in the same directory. – jasonharper Jan 21 '22 at 15:12
  • Thanks it worked by renaming the file !!Though my file was named 'copy.py' and I don't know how renaming it creates a difference. – Mansi Jan 21 '22 at 20:08
  • `copy` is the name of a standard module - apparently one that `pandas` imports. So your script imports pandas, pandas imports `copy` but gets another copy of your script instead, that copy of your script imports pandas, getting an incomplete module because the original script's `import pandas` was still in progress. – jasonharper Jan 21 '22 at 20:12

1 Answers1

1

If you have a file named csv.py or pandas.py or some other dependency in the current directory, that can cause an error like this.

Michael Neale
  • 19,248
  • 19
  • 77
  • 109