problem introduction
I wrote a very common piece of code in pycharm:
import numpy as np
with open('泰坦尼克号数据3.csv', encoding='utf-8') as f:
array = np.loadtxt(f, str, delimiter=',', encoding='utf-8')
array_title = array[0]
print(array)
It can run perfectly in Jupyter, but it cannot run in Pycharm, and an error will be reported:
AttributeError: module 'numpy' has no attribute 'loadtxt'
problem analysis
What is certain is that numpy has the loadtxt attribute, so why is there an error reported here? It turns out that the file name of the py file I created in Pycharm is also called numpy, which conflicts with the installed library name.
Solution
Just change the name of your newly created py file in Pycharm.
Experience summary
In the future, it will look like this: AttributeError: module '(?????)' has no attribute '(??????)' type errors are caused by the same name of the newly created py file and the referenced library function . Change the name to fix the error.