AttributeError: partially initialized module 'pandas' has no attribute 'DataFrame'

Viewed 11391

i want to run this code but i can't and received this error. also i downloaded pandas package.

import pandas

data = {
    "Day": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
    "Visitors": [18, 26, 18, 18, 9, 9, 20, 30, 16, 24],
    "Bounce_Rate": [77.27, 74.07, 73.68, 65, 90, 70, 72, 62.16, 81.25, 72],
}

df = pandas.DataFrame(data)
print(df)
6 Answers

Have you have saved your file as pandas.py? It will confuse the namespace if the file is named pandas.py Otherwise check if there is any file named pandas and delete it. So that you can definitely succeed in fixing this.

If you are getting an attribute error, this means the program is not recognizing the pandas library. Is there another variable you named pandas? Or a directory or file you have named pandas?

Most likely, the name of your python script was 'pandas.py' which will cause a circular import...

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

I've also seen this error. My solution and causes were different than others mentioned, so I'll offer info below.

  1. I was running a cell in a jupyter notebook (filename not pandas.py but 0_isbn_get.ipynb)
  2. I hadn't yet activated my virtual environment
  3. Starting the virtual environment then running the cell did not fix the issue

Fix:

  1. Restart the kernel
  2. activate the virtual environment
  3. Run the notebook cell

please check your panda version reinstall panda in colab restart runtime and run all

SORRY FOR MY ENGLISH. I'M LEARNING.

In my case, I solved the error by changing the file name.

# in file: csv.py 
import pandas as pd
data = {'first_name': ['Sigrid', 'Joe', 'Theodoric','Kennedy', 'Beatrix', 'Olimpia', 'Grange', 'Sallee'],
        'last_name': ['Mannock', 'Hinners', 'Rivers', 'Donnell', 'Parlett', 'Guenther', 'Douce', 'Johnstone'],
        'age': [27, 31, 36, 53, 48, 36, 40, 34],
        'amount_1': [7.17, 1.90, 1.11, 1.41, 6.69, 4.62, 1.01, 4.88],
        'amount_2': [8.06,  "?", 5.90,  "?",  "?", 7.48, 4.37,  "?"]}
datosDataFrame = pd.DataFrame(data)
print(datosDataFrame)
datosDataFrame.to_csv('example.csv')

I get an error

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

"Most likely due to a circular import" means any variable/name is repeated. In my case, my script csv.py conflicted with csv in the standard library.

Related