0

Apologies if this is contained in a previous answer but I've read this one: How to select rows from a DataFrame based on column values? and can't work out how to do what I need to do:

Suppose have some pandas dataframe X and one of the columns is 'timestamp'. The entries are formatted like '2010-11-03 09:44:05'. I want to select just those rows that correspond to a specific day, for example, select just those rows for which the actual string in timestamp column starts with '2010-11-03'. Is there a neat way to do this? Can I do it with a mask or Boolean indexing? Or should I just write a separate line to peel off the day from each entry and then select the rows? Bear in mind the dataframe is large if it helps.

i.e. I want to write something like

X.loc[X['timestamp'].startswith('2010-11-03')]

or

mask = '2010-11-03' in X["timestamp"]

but these don't actually make any sense.

1
  • What makes you think it does not make any sense ? Commented Jun 12, 2020 at 16:53

1 Answer 1

1

This should work:-

X[X['timestamp'].str.startswith('2010-11-03')]
Sign up to request clarification or add additional context in comments.

1 Comment

This seems to be exactly what I was missing; thank you

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.