Python - 在 Pandas DataFrame 中顯示無窮值對應的 True
使用 isin() 方法來顯示無窮值對應的 True。首先,我們用它們各自的別名匯入所需的庫 -
import pandas as pd import numpy as np
建立一個列表字典。我們使用 Numpy np.inf 設定了無窮值 -
d = { "Reg_Price": [7000.5057, np.inf, 5000, np.inf, 9000.75768, 6000, 900, np.inf] }
使用上述列表字典建立 DataFrame -
dataFrame = pd.DataFrame(d)
顯示無窮值對應的 True -
res = dataFrame.isin([np.inf, -np.inf])
示例
以下是程式碼 -
import pandas as pd
import numpy as np
# dictionary of list
d = { "Reg_Price": [7000.5057, np.inf, 5000, np.inf, 9000.75768, 6000, 900, np.inf] }
# creating dataframe from the above dictionary of list
dataFrame = pd.DataFrame(d)
print"DataFrame...\n",dataFrame
# checking for infinite values and displaying the count
count = np.isinf(dataFrame).values.sum()
print"\nInfinity values count...\n ",count
# Displaying TRUE for infinite values
res = dataFrame.isin([np.inf, -np.inf])
print"\n Updated DataFrame...\n",res輸出
這將產生以下輸出 -
DataFrame... Reg_Price 0 7000.505700 1 inf 2 5000.000000 3 inf 4 9000.757680 5 6000.000000 6 900.000000 7 inf Infinity values count... 3 Updated DataFrame... Reg_Price 0 False 1 True 2 False 3 True 4 False 5 False 6 False 7 True
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP