def get_cpi():
 rdint = vs.random()
 request = Request((vs.MACRO_URL % (vs.P_TYPE['http'], vs.DOMAINS['sina'], rdint, vs.MACRO_TYPE[1], 0, 600, rdint)))
 text = urlopen(request, timeout=10).read()
 text = (text.decode('gbk') if ct.PY3 else text)
 regSym = re.compile('\\,count:(.*?)\\}')
 datastr = regSym.findall(text)
 datastr = datastr[0]
 datastr = datastr.split('data:')[1]
 js = json.loads(datastr)
 df = pd.DataFrame(js, columns=vs.CPI_COLS)
 df['cpi'] = df['cpi'].astype(float)
 return df

def get_cpi ( ) : rdint = vs . random ( ) request = Request ( ( vs . MACRO_URL % ( vs . P_TYPE [ 'http' ] , vs . DOMAINS [ 'sina' ] , rdint , vs . MACRO_TYPE [ 1 ] , 0 , 600 , rdint ) ) ) text = urlopen ( request , timeout = 10 ) . read ( ) text = ( text . decode ( 'gbk' ) if ct . PY3 else text ) regSym = re . compile ( '\\,count:(.*?)\\}' ) datastr = regSym . findall ( text ) datastr = datastr [ 0 ] datastr = datastr . split ( 'data:' ) [ 1 ] js = json . loads ( datastr ) df = pd . DataFrame ( js , columns = vs . CPI_COLS ) df [ 'cpi' ] = df [ 'cpi' ] . astype ( float ) return df
return dataframe month :统计月份 cpi :价格指数 .