日期列是一個時間戳。如果日期小于“2021-01-15”,我希望撰寫一個 if-else 條件來操縱 sell 為 0,并在日期大于或等于“2021-01-15”時保持原樣。但我不斷收到此錯誤:TypeError: unsupported operand type(s) for &: 'str' and 'Timestamp'
date sold
2021-01-01 20
2021-01-02 21
2021-01-03 25
2021-01-04 22
2021-01-05 29
uj5u.com熱心網友回復:
試試這個:
df.loc[df['date'] < '2021-01-15', 'sold'] = 0
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/391227.html
