Change date into fiscal month pandas python
<p>I am looking to change the date in my df into a fiscal month in a new column using python pandas.</p>

<p>This is an example</p>

<pre><code>17/01/2016    201601
18/01/2016    201602
</code></pre>

<p>Could you help me to get the required python code?</p>

<p>You can do something like this:</p>

<pre><code>In [29]: df['fiscal_month'] = np.where(df.Date.dt.day &lt; 18, df.Date, df.Date + pd.DateOffset(months=1))

In [30]: df
Out[30]:
        Date        new fiscal_month
0 2016-01-17 2016-01-17   2016-01-17
1 2016-01-18 2016-02-01   2016-02-18

In [31]: df.fiscal_month = df.fiscal_month.dt.strftime('%Y%m')

In [32]: df
Out[32]:
        Date        new fiscal_month
0 2016-01-17 2016-01-17       201601
1 2016-01-18 2016-02-01       201602
</code></pre>

python pandas