I am reading a text file, test.csv, with a given content:
date price curr score
2020-03-08 87.925 72.94 1
2020-03-15 73.460 42.48 1
2020-03-22 317.12 139.21 -1
2020-03-29 28.19 13.76 1
I am taking a date as parameter and it is given as a string with format of "2020-03-15", and I am trying to get a row associated with a given date if the score value is -1:
import pandas as pd
from datetime import datetime
df_result=pd.read_csv("./test.csv", index_col="date", sep="\t", parse_dates=True)
df_result.loc[df_result['anomaly']==-1][datetime.strptime('2020-03-08', '%Y-%m-%d').date()]
It gives an error and I am not able to get the row associated with date '2020-03-08'. Please also consider that I need to set the date column as an index.