Python Pandas - Index' object has no attribute 'hour'
<p>I have a pandas dateframe and the following code works</p>

<pre><code>df['hour'] = df.index.hour
df['c'] = df['hour'].apply(circadian)
</code></pre>

<p>but i was trying to reduce the need to make a 'hour' coloumn, using the following code</p>

<pre><code>df['c'] = df.apply(lambda x: circadian(x.index.hour), axis=1)
</code></pre>

<p>but I get the error message</p>

<pre><code>AttributeError: ("'Index' object has no attribute 'hour'", u'occurred at index 2015-09-25 01:00:00')
</code></pre>

<p>anyone know how to do this?</p>

<p><strong><em>solution</em></strong><br>
use the datetime accessor <code>dt</code></p>

<pre><code>df['c'] = df.index.to_series().dt.hour.apply(circadian)
</code></pre>

python pandas apply