Exemplo n.º 1
0
report_author = u'冥王星人'
save_file = 'E:/Report/Region_Report_first_version.pdf'

def dataframe2list(dframe):
    dictdata = dframe.to_dict('split')
    result = dictdata['data']
    [result[i].insert(0,dictdata['index'][i]) for i in range(len(result))]
    title = [u'变量']
    title.extend(dictdata['columns'])
    result.insert(0,title)
    nrow = len(result)
    ncol = len(result[0])
    return {'data':result,'ncol':ncol,'nrow':nrow}

# 1. 报告的初始化
region_data = RegionData()
report = Report(title=report_title,author=report_author)
for i in range(len(vars)):
    var = vars[i]
    restvar = list(vars)
    del restvar[i]

    # 生成章节
    report.createSection(var)

    period = region_data.databases['citystatiscs'].period(var)
    for year in period:
        # 生成分支章节
        report.createSubSection(year)
        mdata = region_data.query(region=['t'],year=[year],variable=[var])
        mdata = mdata['data']
        if isinstance(var,str):
            var = [var]
        for v in var:
            if not (self._data[v]>0).all():
                return False
        return True

    # 储存图像
    def _save(self,savepath='E:/Report/'):
        x = str(int(datetime.now().timestamp()*1000))
        filename = savepath + 'graph/' + x + '.pdf'
        plt.savefig(filename)


if __name__ == '__main__':
    rdata = RegionData()
    mdata = rdata.query(region=['t'],year=[2010],variable=[u'地区生产总值',u'年末总人口'],scale=u'全市')
    mdata = mdata['data']
    csdexplorer = CrossSectionRegionDataExplorer(mdata)
    #dframe = csdexplorer.perVar(pop=mdata[u'年末总人口'],var=[u'地区生产总值',u'年末总人口'])
    #print(dframe)
    '''
    dframe = csdexplorer.lgVar()
    dframe2 = csdexplorer.describe().applymap(lambda x:'{0:.2f}'.format(x))
    print(dframe2)
    csdexplorer.hist(var=u'地区生产总值',save=True)
    csdexplorer.scatter(y=u'地区生产总值',x=u'年末总人口',kind='kde')
    csdexplorer.pair(vars=[u'地区生产总值',u'年末总人口'])'''

    csdexplorer.ols(y=u'地区生产总值',x=u'年末总人口')
    #print(csdexplorer.corr())
Exemplo n.º 3
0
# coding=UTF-8

import matplotlib.pyplot as plt
import seaborn as sns
from application.DataWarehouse.data.class_regiondata import RegionData
from application.DataWarehouse.toolkit.class_crosssectiondataexplorer import CrossSectionRegionDataExplorer

sns.set(style="white", palette="muted", color_codes=True)

# 载入数据
rdata = RegionData()
mdata = rdata.query(region=["t"], year=[2010], variable=[u"地区生产总值", u"年末总人口"], scale=u"全市")
mdata = mdata["data"]
csdexplorer = CrossSectionRegionDataExplorer(mdata)
"""
plt.style.use('ggplot')

mdata = mdata[u'地区生产总值']
mdata.plot(kind='hist')
plt.show()
"""

print(sns.axes_style())
sns.set_style(
    "white", {"font.sans-serif": ["Microsoft YaHei", "Arial", "Liberation Sans", "Bitstream Vera Sans", "sans-serif"]}
)

mdata = mdata[u"地区生产总值"]
sns.distplot(mdata, kde=False)
plt.show()