AttributeError: partially initialized module 'pandas' has no attribute 'DataFrame' [duplicate]
Asked Answered
L

6

13

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)
Laurin answered 3/4, 2020 at 9:44 Comment(3)
is it me or does the bounce_rate list look longer than the rest? there is no error message posted in ur question. could u add thatDiencephalon
I did not get your error, but I think you missed a comma after the Visitors array. It then worked fine for me.Prognosis
What is the file name of this script?Semiaquatic
O
34

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.

Otey answered 22/12, 2020 at 14:33 Comment(2)
I had named a file csv.py and this happened.Deferent
I named my file copy.py xDSynthesis
A
3

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)
Alves answered 21/12, 2020 at 6:12 Comment(0)
B
2

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?

Bucket answered 3/4, 2020 at 9:51 Comment(1)
That would have raised a SyntaxError, not an AttributeErrorSemiaquatic
C
2

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.

Chartres answered 7/6, 2022 at 3:36 Comment(0)
I
0

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
Illuminometer answered 24/7, 2022 at 2:5 Comment(0)
D
-2

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

Doorknob answered 12/8, 2022 at 4:15 Comment(1)
This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From ReviewCurtcurtail

© 2022 - 2024 — McMap. All rights reserved.