title: Python Pandas DataFrame: filter by a Timestamp column with a list of string timestamps
body: <p>Example setup:</p>
  
  <pre><code>import pandas as pd
  df = pd.DataFrame(
      data={'ts':
            [
                  '2008-11-05 07:45:23.100',
                  '2008-11-17 06:53:25.150',
                  '2008-12-02 07:36:18.643',
                  '2008-12-15 07:36:24.837',
                  '2009-01-06 07:03:47.387',
            ], 
            'val': range(5)})
  
  df.ts = pd.to_datetime(df.ts)
  
  df.set_index('ts', drop=False, inplace=True)
  
  df
  
  
                          | ts                      | val
  2008-11-05 07:45:23.100 | 2008-11-05 07:45:23.100 | 0
  2008-11-17 06:53:25.150 | 2008-11-17 06:53:25.150 | 1
  2008-12-02 07:36:18.643 | 2008-12-02 07:36:18.643 | 2
  2008-12-15 07:36:24.837 | 2008-12-15 07:36:24.837 | 3
  2009-01-06 07:03:47.387 | 2009-01-06 07:03:47.387 | 4
  </code></pre>
  
  <p>Although the index is a pd.Timestamp type, I can use a string representation of a timestamp to filter it. For example:</p>
  
  <pre><code>df.loc['2008-11-05']
  
                          | ts                      | val
  2008-11-05 07:45:23.100 | 2008-11-05 07:45:23.100 | 0
  </code></pre>
  
  <p>Moreover, pandas comes with a very convenient feature that when my filter is vague it returns the desirable result. For example:</p>
  
  <pre><code>df.loc['2008-12']
                          | ts                      | val
  2008-12-02 07:36:18.643 | 2008-12-02 07:36:18.643 | 2
  2008-12-15 07:36:24.837 | 2008-12-15 07:36:24.837 | 3
  </code></pre>
  
  <p><strong>My first question is</strong>, how can I filter the df with a list of string timestamps? For example if I run the code below</p>
  
  <pre><code>df.loc[['2008-11-05','2008-12']]
  </code></pre>
  
  <p>, the result I want to get is</p>
  
  <pre><code>                        | ts                      | val
  2008-11-05 07:45:23.100 | 2008-11-05 07:45:23.100 | 0
  2008-12-02 07:36:18.643 | 2008-12-02 07:36:18.643 | 2
  2008-12-15 07:36:24.837 | 2008-12-15 07:36:24.837 | 3
  </code></pre>
  
  <p>, but in fact I get the following error:</p>
  
  <pre><code>KeyError: "None of [Index(['2008-11-05', '2008-12'], dtype='object', name='ts')] are in the [index]"
  </code></pre>
  
  <p><strong>My second question is</strong>, can I do the similar filtering logic for a regular column? I.e., if I don't set <code>ts</code> as the index but filter the <code>ts</code> column directly with a string filter.</p>
  
  <p>-------------------- Follow up 2019-9-10 10:00 -------------------- </p>
  
  <p>All the answers below are very much appreciated. I didn't know <code>pd.Series.str.startswith</code> can support the <code>tuple</code> input of multiple strings, or that <code>pd.Series.str.contains</code> can support the usage of <code>'|'</code>. New skills learned!</p>
  
  <p>I think all the methods based on the use of <code>astype(str)</code> has one major shortcoming for me: In US people use all kinds of date time formats. Besides '2008-11-05', commonly used ones in my company are '2008-11-5', '11/05/2008', '11/5/2008', '20081105', '05nov2008', which would all fail if I used the string based method. </p>
  
  <p>For now I still have to stick with the following method, which requires the column to be the index and doesn't seem efficient (I haven't profiled), but should be sufficiently robust. I don't understand why it is not supported natively by pandas. </p>
  
  <pre><code>L = ['5nov2008','2008/12']
  pd.concat([df.loc[val] for val in L]).drop_duplicates()
  
                          | ts                      | val
  2008-11-05 07:45:23.100 | 2008-11-05 07:45:23.100 | 0
  2008-12-02 07:36:18.643 | 2008-12-02 07:36:18.643 | 2
  2008-12-15 07:36:24.837 | 2008-12-15 07:36:24.837 | 3
  </code></pre>