Skip to content

How to get integer index of datetime[64ns]? #7190

Answered by keewis
forestbat asked this question in Q&A
Discussion options

You must be logged in to vote

you'd need to use the correct syntax for indexing:

time_index = slice_array.loc[{"TM": special_time}]

or

time_index = slice_array.sel(TM=special_time)
# or
time_index = slice_array.sel({"TM": special_time})

However, that will not give you the integer index, it will allow you to select data for a specific time. If you use that to index other arrays I'd suggest to put all of them into a single Dataset and call the sel / loc on that.

If you truly do need the integer index, you can try querying the underlying index object:

slice_array.indexes["TM"].get_loc(special_time)

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by forestbat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants