title: Changing frequency of pandas Period and PeriodIndex
body: <p>I am importing some stock data that has annual report information into a pandas DataFrame.   But the date for the annual report end date is an odd month (end of january) rather than end of year.</p>
  
  <pre><code>years = ['2017-01-31', '2016-01-31', '2015-01-31']
  df = pd.DataFrame(data = years, columns = ['years'])
  
  df
  Out[357]: 
          years
  0  2017-01-31
  1  2016-01-31
  2  2015-01-31
  </code></pre>
  
  <p>When I try to add in a PeriodIndex which shows the period of time the report data is valid for, it defaults to ending in December rather than inferring it from the date string</p>
  
  <pre><code>df.index = pd.PeriodIndex(df['years'], freq ='A')
  
  df.index
  
  Out[367]: PeriodIndex(['2017', '2016', '2015'], dtype='period[A-DEC]', 
  name='years', freq='A-DEC')
  </code></pre>
  
  <p>Note that the frequency should be 'A-JAN'.</p>
  
  <p>I assume this means that the end date can't be inferred from PeriodIndex and the end date string I gave it.</p>
  
  <p>I can change it using the asfreq method and anchored offsets <a href="https://pandas.pydata.org/pandas-docs/stable/timeseries.html#anchored-offsets" rel="nofollow noreferrer">anchored offsets</a> using "A-JAN" as the frequency string.   But, this changes all of the individual periods in the PeriodIndex rather than individually as years can have different reporting end dates for their annual report (in the case of a company that changed their reporting period).     </p>
  
  <p>Is there a way to interpret each date string and correctly set each period for each row in my pandas frame?  </p>
  
  <p>My end goal is to set a period column or index that has a frequency of 'annual' but with the period end date set to the date from the corresponding row of the years column. </p>
  
  <p>** Expanding this question a bit further.   Consider that I have many stocks with 3-4 years of annual financial data for each and all with varying start and end dates for their annual reporting frequencies (or quarterly for that matter).   </p>
  
  <pre><code>Out[14]: 
          years tickers
  0  2017-01-31      PG
  1  2016-01-31      PG
  2  2015-01-31      PG
  3  2017-05-31       T
  4  2016-05-31       T
  5  2015-05-31       T
  </code></pre>
  
  <p>What I'm trying to get to is a column with proper Period objects that are configured with proper end dates (from the year column) and all with annual frequencies.     I've thought about trying to iterate through the years and use apply.map or lambda function and the pd.Period function.     It may be that a PeriodIndex can't exist with varying Period Objects in it that have varying end dates.     something like </p>
  
  <pre><code>for row in df.years:
      s.append(pd.Period(row, freq='A")
  df['period']= s
  </code></pre>