0

Is there a way to select rows with a DateTimeIndex without referring to the date as such e.g. selecting row index 2 (the usual Python default manner) rather than "1995-02-02"?

enter image description here

Thanks in advance.

1 Answer 1

1

Yes, you can use .iloc, the positional indexer:

df.iloc[2]

Basically, it indexes by actual position starting from 0 to len(df), allowing slicing too:

df.iloc[2:5]

It also works for columns (by position, again):

df.iloc[:, 0]  # All rows, first column
df.iloc[0:2, 0:2] # First 2 rows, first 2 columns
Sign up to request clarification or add additional context in comments.

Comments

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.