new_df = pd.concat(new_dataset)
print(new_df.shape)
new_df = new_df.dropna(how='any')
print(new_df.shape)
new_df.head(20)

現在我想根據“Close_gap”列中的值添加另一個名為“Close_gap_IUD”的列。我想:
- 'Close_gap_IUD' 列中的'Increase' 標簽,用于'Close_gap' 列的正值(>0),2. 'Close_gap_IUD' 列中的'Decrease' 標簽,用于'Close_gap' 列的負值(<0),
- 'Close_gap_IUD' 列中的 'Unchanged' 標簽,用于 'Close_gap' 列的零值 (==0)
我怎樣才能做到這一點?
uj5u.com熱心網友回復:
new_df["Close_gap_IUD"] = new_df["Close_gap"].apply(lambda x: "Increase" if x > 0 else "Decrease" if x < 0 else "Unchanged")
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/469364.html
標籤:python-3.x 熊猫
