简体   繁体   中英

Pandas in VS Code: AttributeError: module 'string' has no attribute 'ascii_letters'

I'm a new learner in data science. I havent find out why I got an attribute error. I used python 3.8.3 in Visual Studio Code. I installed Pandas in terminal (pip install Pandas). I dont know what the problem is. Any help will be appreciated.

import pandas as pd
df=pd.DataFrame()
print(df)

All I did was to create an empty dataframe. And I got that:

Traceback (most recent call last):
  File "c:/Users/Fatma Elik/Documents/VS Code/BTK/Pandas_dataframe.py", line 20, in <module>
    import pandas as pd
  File "C:\Users\Fatma Elik\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\__init__.py", line 180, in <module>
    import pandas.testing
  File "C:\Users\Fatma Elik\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\testing.py", line 5, in <module>
    from pandas._testing import (
  File "C:\Users\Fatma Elik\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pandas\_testing.py", line 404, in <module>
    RANDS_CHARS = np.array(list(string.ascii_letters + string.digits), dtype=(np.str_, 1))
AttributeError: module 'string' has no attribute 'ascii_letters'

Secondly I tried this instead and I got an attribute error again:

import pandas as pd
                                                                                                                                                                                                                                                                                          
s1=pd.Series([3,2,0,1])
s2=pd.Series([0,3,7,2])
    
data=dict(apples=s1,oranges=s2)     
    
df=pd.DataFrame(data) 
print(df) 

I did Ctrl+Click on string and I find that I already created a py file before. Because I searched on file search engine Windows 10 before, I couldnt have found it. Another simple mistake again:)

It's a little weird, the "string" module is a part of the standard library. Could you try this code?

from string import ascii_letters
print(ascii_letters)

Check it works or not, if it doesn't work, can you enter into this file: "C:\Users\Fatma Elik\AppData\Local\Programs\Python\Python38-32\lib\string.py", and can you find:

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_letters = ascii_lowercase + ascii_uppercase

It should be located from line 25 to 27. If you can't find it, you should try to upgrade your python or reinstall it.

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