suchitra nagarajan
suchitra nagarajan

Reputation: 155

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

I want to retrieve value from 2020-04-20(todays date) column of 3rd row from the above.This is the result of

print(data.columns)    

I tried using get_value and .at.It didnt work

print(data.columns)

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)

Upvotes: 1

Views: 99

Answers (1)

Rajat Mishra
Rajat Mishra

Reputation: 3780

You need to convert your index into datetime object. Currently its string. you can change index into datetime :

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

After that it should work.

Upvotes: 1

Related Questions