Reputation: 53
I'm trying to look for a piece of data by date and value, however, I keep getting an error. Here is the code:
eth.loc['2020-08-13', 'Value']
Here is the error:
352 except ValueError as err:
353 raise KeyError(key) from err
--> 354 raise KeyError(key)
355 return super().get_loc(key, method=method, tolerance=tolerance)
356
KeyError: '2020-08-13'
Thanks!
Upvotes: 1
Views: 679
Reputation: 21
Assumming you've a dataset defined by:
eth = pd.DataFrame([['2020-08-13', 2], ['2020-08-14', 5], ['2020-08-15', 8]],
index=['book1','book2','book3'],
columns=['Date','Value'])
You can get items with value say 2:
eth.loc[eth['Value'] == 2]
You can get items with date say 2020-08-13:
eth.loc[eth['Date'] == '2020-08-13']
Upvotes: 2
Reputation: 53
Answer turned out to be eth.loc[eth.columnname=='2020-08-13', 'Value']
, thanks to @wwnde for the help!
Upvotes: 1