Search code examples
python-3.xpandasdataframepycharm

in pycharm, when i run a simple code with pandas it shows me this


import pandas as pd
        
# define DataFrame
df = pd.DataFrame({'points': [25, 12, 15, 14, 19, 23, 25, 29],
                   'assists': [5, 7, 7, 9, 12, 9, 9, 4],
                   'rebounds': [11, 8, 10, 6, 6, 5, 9, 12]})
        
# display DataFrame
print(df)
> Traceback (most recent call last):
  File "E:\pc\krish naik\1. python for data science & data analysis(12 days)\p1.py", line 1, in <module>     import pandas as pd
  File "E:\pc\venv\lib\site-packages\pandas\__init__.py", line 135, in <module>
    from pandas import api, arrays, errors, io, plotting, testing, tseries
  File "E:\pc\venv\lib\site-packages\pandas\testing.py", line 6, in <module>
    from pandas._testing import (
  File "E:\pc\venv\lib\site-packages\pandas\_testing\__init__.py", line 51, in <module>
    from pandas._testing._io import (  # noqa:F401
  File "E:\pc\venv\lib\site-packages\pandas\_testing\_io.py", line 22, in <module>
    from pandas._testing._random import rands
  File "E:\pc\venv\lib\site-packages\pandas\_testing\_random.py", line 10, in <module>
    RANDS_CHARS = np.array(list(string.ascii_letters + string.digits), dtype=(np.str_, 1))
  AttributeError: module 'string' has no attribute 'ascii_letters'

Solution

  • There is either a library you downloaded called string or you have a file shadownaming the built-in module called string. First option is unlikely. Check your files.