8

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)
Alex
  • 6,610
  • 3
  • 20
  • 38
bnh
  • 107
  • 1
  • 1
  • 5

6 Answers6

29

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.

Nathan
  • 3,082
  • 1
  • 27
  • 42
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?

Derek O
  • 16,770
  • 4
  • 24
  • 43
1

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)
Valencia
  • 11
  • 2
0

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.

Edward Ji
  • 745
  • 8
  • 19
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
M H
  • 325
  • 3
  • 8
0

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

  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/32468285) – Thorbjørn Ravn Andersen Aug 18 '22 at 05:12