-1

installed pandas package successfully. Import the pandas. Getting below error while run the sample code.

code:

import pandas as pd

df1 = pd.DataFrame({"A": ["A0", "A1", "A2", "A3", "A4"]}, index=[0])
print(df1)

error:

Traceback (most recent call last):
  File "D:/Users/prabhakar_d/Box/S&P Local_mine/PycharmProjects/practise_project/sample/default_keywr_parm.py", line 11, in <module>
    import pandas as pd
  File "C:\Program Files\Python36\lib\site-packages\pandas\__init__.py", line 22, in <module>
    from pandas.compat.numpy import (
  File "C:\Program Files\Python36\lib\site-packages\pandas\compat\numpy\__init__.py", line 9, in <module>
    _np_version = np.__version__
AttributeError: module 'numpy' has no attribute '__version__'
Anurag Dabas
  • 23,866
  • 9
  • 21
  • 41
Prabhakar
  • 1
  • 2
  • 1
    have a look on: https://stackoverflow.com/questions/50311096/attributeerror-module-numpy-has-no-attribute-version and also `index=[0]` will throw error – Anurag Dabas May 15 '21 at 03:58

3 Answers3

0

See you are passing 5 rows and 1 column(5,1) but the index parameter is saying that it is 1 row and 1 column (1,1) so try removing the index parameter.

Vibhav Surve
  • 73
  • 1
  • 6
0

First step check your numpy version I don't know how does it bug in your numpy, But now I already try your script

import pandas as pd

df1 = pd.DataFrame({"A": ["A0", "A1", "A2", "A3", "A4"]}, index=[0])
print(df1)

And I don't met like your error on my numpy(1.19.4)

enter image description here

So please try to update your numpy. And then follow to the First answer from: @Vibhav_Surve

when you try to run your code with your script. If you still run with add index() you will found this error like this. enter image description here

TH_SPT
  • 38
  • 6
0

try removing index from your df1 varable...

import pandas as pd
df1 = pd.DataFrame({"A":["A0","A1","A2","A3","A4"]})
print(df1)

o/p

    A
0  A0
1  A1
2  A2
3  A3
4  A4
Deepak
  • 470
  • 1
  • 3
  • 15