简体   繁体   中英

Python Traceback error while running the code using pandas

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__'

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.

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)

在此处输入图像描述

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. 在此处输入图像描述

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM