簡體   English   中英

如何從特定行和列 python 的單元格中檢索值?

[英]how to retrieve the value from a cell of specific row and column python?

    2020-04-13
2020-04-14
2020-04-15
2020-04-16
2020-04-17
2020-04-20
2020-04-21
2020-04-22
2020-04-23
2020-04-24
2020-04-27
2020-04-28
2020-04-29
2020-04-30
2020-05-01
2020-05-04
2020-05-05
2020-05-06
2020-05-07
2020-05-08
2020-05-11
2020-05-12
2020-05-13
2020-05-14
2020-05-15
2020-05-18
2020-05-19
2020-05-20
2020-05-21
2020-05-22

我想從上面的第 3 行的 2020-04-20(今天日期)列中檢索值。這是結果

print(data.columns)    

我嘗試使用 get_value 和.at。它沒有用

打印(數據。列)

for 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)

您需要將索引轉換為datetime時間 object。 目前它的字符串。 您可以將索引更改為日期時間:

df.index = pd.to_datetime(df.index)

之后它應該工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM