使用 Pandas 系列比較兩個 Python 程式
在此程式中,我們將宣告兩個 Pandas 系列並比較它們的元素。在解決問題之前,我們需要將 Pandas 庫匯入本地 IDE。可以透過在本地機器上安裝 Pandas 來完成此操作。安裝 Pandas 的命令為 -
pip install pandas
輸入
Series1 = [2,4,6,8,10]
Series2 = [1,3,5,7,9]
演算法
Step 1: Define two Pandas series using the Series() function of Pandas library.
Step 2: Compare the series using greater than, less than, and equal-to operators.
示例程式碼
import pandas as pd series1 = pd.Series([2,4,6,8,10]) series2 = pd.Series([1,3,5,7,9]) print("Greater Than: \n",series1>series2) print("\nLess Than: \n",series1<series2) print("\nEquals : \n", series1 == series2)
輸出
Greater Than: 0 True 1 True 2 True 3 True 4 True dtype: bool Less Than: 0 False 1 False 2 False 3 False 4 False dtype: bool Equals : 0 False 1 False 2 False 3 False 4 False dtype: bool
廣告