Selecting a rows from a panda frame based on a time that has been converted into datetime format and stripped from a POSIX time stamp, python
<p>I am using the code below to pull data from Google Finance. The timestamp is in POSIX form, so it is converted into data time. When I try to fiter it based on a time criteria <strong>(14:35:00)</strong>, it returns an empty table. I suspect it has to do with the POSIX/ datetime conversion, but have no idea how to resolve it.</p>

<pre><code>def get_intraday_data(symbol, interval_seconds=301, num_days=10):
    # Specify URL string based on function inputs.
    url_string = 'http://www.google.com/finance/getprices?q={0}'.format(symbol.upper())
    url_string += "&amp;i={0}&amp;p={1}d&amp;f=d,o,h,l,c,v".format(interval_seconds,num_days)

    # Request the text, and split by each line
    r = requests.get(url_string).text.split()

    # Split each line by a comma, starting at the 8th line
    r = [line.split(',') for line in r[7:]]

    # Save data in Pandas DataFrame
    df = pd.DataFrame(r, columns=['Datetime','Close','High','Low','Open','Volume'])

    # Convert UNIX to Datetime format
    df['Datetime'] = df['Datetime'].apply(lambda x: datetime.datetime.fromtimestamp(int(x[1:])))

    #Seperate Date and Time
    df['Time'],df['Date']= df['Datetime'].apply(lambda x:x.time()), df['Datetime'].apply(lambda x:x.date()) 

    #Convert 'Close','High','Low','Open', deleting 'Volume'

''''df['Close'] = df['Close'].astype('float64')
df['High'] = df['High'].astype('float64')
df['Low'] = df['Low'].astype('float64')
df['Open'] = df['Open'].astype('float64')'''
    del df['Volume']
    del df['Datetime']

    df[['Close','High','Low','Open']]  = df[['Close','High','Low','Open']].astype('float64')

   # Calculating %Change and Range 

    df['%pct'] = (df['Close'] - df['Open'])/df['Open']
    df['Range'] = df['High'] - df['Low']

    #Sort Columns


    return df
</code></pre>

<p>I have stored the results of this function as <strong>NAS</strong></p>

<pre><code>NAS = get_intraday_data('IXIC', interval_seconds=301, num_days= 100)
</code></pre>

<p>The Filter Criteria is:</p>

<pre><code>NAS[NAS['Time'] == '14:35:00']
</code></pre>

<p>I will appreciate assistance on this.</p>

<p>I see that you are converting <code>timestamp</code> to <code>datetime</code> incorrectly. You are calling <code>datetime</code> twice.</p>

<p>Replace</p>

<pre><code>df['Datetime'] = df['Datetime'].apply(lambda x: datetime.datetime.fromtimestamp(int(x[1:])))
</code></pre>

<p>with </p>

<pre><code>df['Datetime'] = df['Datetime'].apply(lambda x: datetime.fromtimestamp(int(x[1:])))
</code></pre>

<p>In 2nd part of your question:</p>

<pre><code>NAS = get_intraday_data('IXIC', interval_seconds=301, num_days= 100)

NAS[NAS['Time'] == '14:35:00']
</code></pre>

<p>You care comparing instance of <code>datetime.time</code> with string, which is not correct. Try</p>

<pre><code>NAS[NAS['Time'] == datetime.strptime('14:35:00', '%H:%M:%S').time()]
</code></pre>

<p>it should work as expected.</p>

<p><strong>Update:</strong></p>

<p>Running script with suggested changes will display data as:</p>

<p><code>
         Close      High       Low      Open      Time        Date      %pct<br>
60    5162.448  5165.124  5162.448  5165.057  14:35:00  2016-07-29 -0.000505<br>
138   5181.768  5183.184  5181.193  5181.404  14:35:00  2016-08-01  0.000070<br>
216   5130.514  5131.933  5130.434  5131.893  14:35:00  2016-08-02 -0.000269<br>
294   5146.608  5146.608  5143.827  5144.788  14:35:00  2016-08-03  0.000354<br>
372   5163.854  5164.154  5162.997  5164.021  14:35:00  2016-08-04 -0.000032<br>
450   5221.624  5221.911  5220.658  5220.789  14:35:00  2016-08-05  0.000160<br>
528   5204.111  5204.240  5202.476  5202.865  14:35:00  2016-08-08  0.000239<br>
.
.
. 
3648  5282.999  5283.017  5279.008  5279.340  14:35:00  2016-10-04  0.000693<br>
3726  5324.450  5325.375  5323.628  5324.129  14:35:00  2016-10-05  0.000060<br>
3804  5310.945  5311.454  5310.194  5310.558  14:35:00  2016-10-06  0.000073<br>
3882  5295.064  5295.080  5292.184  5292.327  14:35:00  2016-10-07  0.000517
</code></p>

python python-3.x datetime pandas posixlt