在Python
時,我們經常遇到場景,我們經常遇到基於現有列之間創建新列的情況,在該場景中,我們需要在其中創建一個新的列。 This can be achieved using the np.where function with nested conditions.To illustrate, consider the following DataFrame:
import pandas as pd df = pd.dataframe({ “ A”:[2,3,1], “ B”:[2,1,3] })import pandas as pd
df = pd.DataFrame({
"A": [2, 3, 1],
"B": [2, 1, 3]
})
One approach is to create a custom function that implements the conditional logic and apply it to the DataFrame:免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。
Copyright© 2022 湘ICP备2022001581号-3