Python / pandas - SettingWithCopyWarning using DatetimeIndex().day
<p>I have code given the SettingWithCopy Warning and I can't figure out to recode it properly. </p>

<pre><code>dataframe['day'] = pandas.DatetimeIndex(dataframe['date_time']).day
</code></pre>

<p>I am trying to make columns in the original dataframe holidng the day, year, etc.</p>

<p>You need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.dt.day.html" rel="nofollow"><code>Series.dt.day</code></a>, <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.dt.year.html" rel="nofollow"><code>Series.dt.year</code></a>:</p>

<pre><code>df['day'] = df['date_time'].dt.day
df['year'] = df['date_time'].dt.year
</code></pre>

python pandas