2020-04-132020-04-142020-04-152020-04-162020-04-172020-04-202020-04-212020-04-222020-04-232020-04-242020-04-272020-04-282020-04-292020-04-302020-05-012020-05-042020-05-052020-05-062020-05-072020-05-082020-05-112020-05-122020-05-132020-05-142020-05-152020-05-182020-05-192020-05-202020-05-212020-05-22我想從上面的第 3 行的 2020-04-20(今天日期)列中檢索值。這是結果print(data.columns) 我嘗試使用 get_value 和 .at。它沒有用打?。〝祿A校ゝor i in data.columns: convert_date=i.date()#converting to date type if date.today()==convert_date:#comparing todays date print(date.today()) print(data.at[3,date.today()])#throws KeyError: datetime.date(2020, 4, 20)
1 回答

狐的傳說
TA貢獻1804條經驗 獲得超3個贊
您需要將索引轉換為datetime
對象。目前它的字符串。您可以將 index 更改為 datetime :
df.index = pd.to_datetime(df.index)
之后它應該工作。
添加回答
舉報
0/150
提交
取消