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.

T_M
  • 103
  • 2

1 Answers1

1

This should work:-

X[X['timestamp'].str.startswith('2010-11-03')]
Dhaval Taunk
  • 1,662
  • 1
  • 9
  • 17