def freq_to_period(freq):
 if (not isinstance(freq, offsets.DateOffset)):
  freq = to_offset(freq)
 freq = freq.rule_code.upper()
 if ((freq == 'A') or freq.startswith(('A-', 'AS-'))):
  return 1
 elif ((freq == 'Q') or freq.startswith(('Q-', 'QS-'))):
  return 4
 elif ((freq == 'M') or freq.startswith(('M-', 'MS'))):
  return 12
 elif ((freq == 'W') or freq.startswith('W-')):
  return 52
 elif (freq == 'D'):
  return 7
 elif (freq == 'B'):
  return 5
 elif (freq == 'H'):
  return 24
 else:
  raise ValueError('freq {} not understood. Please report if you think this is in error.'.format(freq))

def freq_to_period ( freq ) : if ( not isinstance ( freq , offsets . DateOffset ) ) : freq = to_offset ( freq ) freq = freq . rule_code . upper ( ) if ( ( freq == 'A' ) or freq . startswith ( ( 'A-' , 'AS-' ) ) ) : return 1 elif ( ( freq == 'Q' ) or freq . startswith ( ( 'Q-' , 'QS-' ) ) ) : return 4 elif ( ( freq == 'M' ) or freq . startswith ( ( 'M-' , 'MS' ) ) ) : return 12 elif ( ( freq == 'W' ) or freq . startswith ( 'W-' ) ) : return 52 elif ( freq == 'D' ) : return 7 elif ( freq == 'B' ) : return 5 elif ( freq == 'H' ) : return 24 else : raise ValueError ( 'freq {} not understood. Please report if you think this is in error.' . format ( freq ) )
convert a pandas frequency to a periodicity parameters freq : str or offset frequency to convert returns period : int periodicity of freq notes annual maps to 1 .