I have the following dataframe:
date value
0 2016-01-01 gfhgh
1 2016-01-02 acgb
2 2016-01-03 yjhgs
I need to get the index of a row where date is a predefined value. For example for 2016-01-02, I need to get 1. Each date will be unique.
Assuming the date field is string:
df[df.date == '<the date value whose index you want>'].index.tolist()
Will return a list of indices whose date is equal to the date value you provided
IIUC you can use:
print df
date value
0 2016-01-01 gfhgh
1 2016-01-02 acgb
2 2016-01-03 yjhgs
print df[df['date'] == pd.to_datetime('2016-01-02')].index.tolist()
[1]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With