我第二次不能使用import pandas as pd
。一开始,我输入它非常好用。关闭终端后,重新打开它,然后再次输入,说'pd'没有定义......
Apple Python和Anaconda都发生了这种情况。我试过删除一个而只使用另一个,但错误的发生方式相同。
答案 0 :(得分:0)
我不确定我理解你的问题,但如果这个行为是你的意思,这是正常行为。我没有熊猫,但任何其他库应该是相同的:
>>> import requests as pd
>>> print pd.__version__
2.9.1
>>> exit()
Abel-Guzman-Sanchezs-MacBook-Air:~ cncuser$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print pd.__version__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'pd' is not defined
>>>
每次执行代码时,都必须导入所需的库。以防您可以多次导入同一个库:
>>> import requests as pd
>>> import requests as pd
>>>
EDIT1:
我使用pandas
安装了pip install pandas
来向您显示相同内容:
>>> import pandas as pd
>>> print pd.__version__
0.18.1
>>> exit()
Abel-Guzman-Sanchezs-MacBook-Air:~ cncuser$ python
Python 2.7.10 (default, Oct 23 2015, 19:19:21)
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print pd.__version__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'pd' is not defined
>>> import requests as pd
>>> print pd.__version__
2.9.1
>>>