如何知道我的 Python 是否安裝了 pandas?
要檢查 Python 中是否安裝了 pandas 包,我們可以簡單地驗證其版本。要獲取 pandas 的版本詳細資訊,我們有兩個選項。
第一種方法是使用 `__version__` 屬性。
示例
import pandas as pd print(pd.__version__)
解釋
要驗證 pandas 的版本號,我們可以使用 pandas 提供的內建屬性 `__version__`,這將返回一個數字,指定我們擁有的 pandas 版本。
輸出
1.1.5
數字 1.1.5 代表已安裝的 pandas 版本。
第二種方法是使用 pandas 的 `show_versions()` 方法。
示例
print(pd.show_versions())
`show_versions()` 是一個 pandas 方法,它不僅會提供有關 pandas 版本的資訊,還會提供有關 python 和 pandas 依賴包以及作業系統型別的版本詳細資訊。
輸出
INSTALLED VERSIONS ------------------ commit : b5958ee1999e9aead1938c0bba2b674378807b3d python : 3.8.3.final.0 python-bits : 32 OS : Windows OS-release : 10 Version : 10.0.19041 machine : AMD64 processor : Intel64 Family 6 Model 78 Stepping 3, GenuineIntel byteorder : little LC_ALL : None LANG : None LOCALE : English_United States.1252 pandas : 1.1.5 NumPy : 1.19.4 pytz : 2020.1 dateutil : 2.8.1 pip : 20.3.3 setuptools : 41.2.0 Cython : None pytest : None hypothesis : None sphinx : None blosc : None feather : None xlsxwriter : None lxml.etree : None html5lib : None pymysql : None psycopg2 : None jinja2 : 2.11.2 IPython : 7.19.0 pandas_datareader : None bs4 : None bottleneck : None fsspec : None fastparquet : None gcsfs : None matplotlib : 3.3.3 numexpr : None odfpy : None openpyxl : None pandas_gbq : None pyarrow : None pytables : None pyxlsb : None s3fs : None scipy : 1.5.4 sqlalchemy : None tables : None tabulate : None xarray : None xlrd : None xlwt : None numba : None
以上程式碼塊顯示了所有 pandas 依賴項和 python 的版本。
如果我們沒有安裝 pandas 包,則會看到錯誤訊息。錯誤訊息如下所示:
ModuleNotFoundError
當 python 無法成功匯入模組時,將出現上述錯誤。在這種情況下,可能是我們尚未安裝 pandas 包,或者可能是拼寫錯誤。
如果遇到上述錯誤,請安裝 pandas 包。這是識別 pandas 是否已安裝的兩種方法。
廣告
資料結構
網路
關係資料庫管理系統 (RDBMS)
作業系統
Java
iOS
HTML
CSS
Android
Python
C語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP