0

I used this code: df_3 = df_2.groupby(df_2.index.strftime('%A %H:%M')).mean() to create a dataframe that contains the mean of each timestamp for each weekday which looks like this:

date_col Available
Friday 00:00 512.805556
Friday 00:05 515.184211
Friday 00:10 514.631579
Friday 00:15 517.477273

But I'm not sure how to locate one record based on the index. When I try with the displayed timestamp as a string, like df_3.iloc[['Friday 00:05']] it throws an error but how would I refer to that value? date_col is the index

1 Answer 1

1

If your date is your index use loc, iloc is used to access by row number:

df_3.loc[['Friday 00:05']]

else, first set date_col as index:

df_3.set_index('date_col')

also, you can access the row without setting the date_col as index:

df_3[df_3['date_col']=='Friday 00:05']  
Sign up to request clarification or add additional context in comments.

2 Comments

groupby sets the key as index by default, so if OP's command is correct date_col should be the index. ;)
@mozway, i know, but the provided sample shows something else.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.