从新型冠状病毒2019-nCoV数据分析武汉疫情发展趋势

新型冠状病毒
ncov2019
标签: #<Tag:0x00007fc82665ecf8> #<Tag:0x00007fc82665eb68>

(小Q) #1

2019新型冠状病毒

2019新型冠状病毒 (2019-nCoV) 因2019年武汉病毒性肺炎病例而被发现,2020年1月12日被世界卫生组织命名为2019-nCoV。冠状病毒是一个大型病毒家族,已知可引起感冒以及[中东呼吸综合征](MERS)和[严重急性呼吸综合征](SARS)等较严重疾病。新型冠状病毒是以前从未在人体中发现的冠状病毒新毒株。 关于病毒的相关资料可参考科普视频

2019新型冠状病毒历史数据

BigQuant平台从网上收集整理了最全和包含历史的2019新型冠状病毒2019-nCoV疫情数据,包括全国和34省市疫情历史数据。

平台已将数据开放以供更多人可以使用分析,数据源(DataSource)ID为bigquant-ncov2019

2019新型冠状病毒历史数据分析

BigQuant平台提供了数据使用和分析模版如下,请克隆分析模型做深度分析研究,和进一步的疫情预测、传染建模等。

从(2020-02-02)数据分析中可以看到疫情得到一定控制,增长率、重症率和死亡率都在持续降低。

克隆策略

    {"Description":"实验创建于2020/2/2","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-55:input_data","SourceOutputPortId":"-25:data"},{"DestinationInputPortId":"-36:input_data","SourceOutputPortId":"-32:data"},{"DestinationInputPortId":"-66:input_data","SourceOutputPortId":"-32:data"},{"DestinationInputPortId":"-206:input_data","SourceOutputPortId":"-32:data"},{"DestinationInputPortId":"-78:input_data","SourceOutputPortId":"-32:data"},{"DestinationInputPortId":"-126:input_data","SourceOutputPortId":"-32:data"},{"DestinationInputPortId":"-107:input_1","SourceOutputPortId":"-32:left_data"},{"DestinationInputPortId":"-32:input_data","SourceOutputPortId":"-55:data"},{"DestinationInputPortId":"-55:features","SourceOutputPortId":"-63:data"},{"DestinationInputPortId":"-90:input_data","SourceOutputPortId":"-107:data_1"},{"DestinationInputPortId":"-114:input_data","SourceOutputPortId":"-107:data_2"}],"ModuleNodes":[{"Id":"-25","ModuleId":"BigQuantSpace.use_datasource.use_datasource-v1","ModuleParameters":[{"Name":"datasource_id","Value":"bigquant-ncov2019","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-25"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-25"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-25","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":1,"IsPartOfPartialRun":null,"Comment":"疫情数据","CommentCollapsed":false},{"Id":"-32","ModuleId":"BigQuantSpace.filter.filter-v3","ModuleParameters":[{"Name":"expr","Value":"province == country","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_left_data","Value":"True","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-32"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-32","OutputType":null},{"Name":"left_data","NodeId":"-32","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":2,"IsPartOfPartialRun":null,"Comment":"区分全国数据和省市数据","CommentCollapsed":false},{"Id":"-36","ModuleId":"BigQuantSpace.plot_dataframe.plot_dataframe-v1","ModuleParameters":[{"Name":"title","Value":"全国疫情趋势","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"line","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"x","Value":"日期","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"确诊,重症,死亡,治愈,疑似","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"options","Value":"{\n 'chart': {\n 'height': 500\n }\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"candlestick","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_1","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_2","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_3","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_4","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-36"}],"OutputPortsInternal":[],"UsePreviousResults":false,"moduleIdForCode":3,"IsPartOfPartialRun":null,"Comment":"全国疫情趋势","CommentCollapsed":false},{"Id":"-55","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"remove_extra_columns","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-55"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-55"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-55","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":4,"IsPartOfPartialRun":null,"Comment":"数据计算","CommentCollapsed":false},{"Id":"-63","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"instrument=province\n\n日期=date\n国家=country\n省份=province\n疑似=sus_num\n确诊=con_num\n重症=crit_num\n死亡=death_num\n治愈=cure_num\n密切接触=cont_num\n医学观察=obse_num\n疑似增长=sus_num - shift(sus_num, 1)\n确诊增长=con_num - shift(con_num, 1)\n疑似增长率=sus_num/shift(sus_num, 1) - 1\n确诊增长率=con_num/shift(con_num, 1) - 1\n死亡率=死亡/确诊\n重症率=重症/确诊\n治愈率=治愈/确诊\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-63"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-63","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-66","ModuleId":"BigQuantSpace.plot_dataframe.plot_dataframe-v1","ModuleParameters":[{"Name":"title","Value":"全国疫情趋势-密切接触者跟踪","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"line","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"x","Value":"日期","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"密切接触,医学观察","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"options","Value":"{\n 'chart': {\n 'height': 500\n }\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"candlestick","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_1","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_2","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_3","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_4","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-66"}],"OutputPortsInternal":[],"UsePreviousResults":false,"moduleIdForCode":6,"IsPartOfPartialRun":null,"Comment":"全国疫情趋势-密切接触者","CommentCollapsed":false},{"Id":"-206","ModuleId":"BigQuantSpace.plot_dataframe.plot_dataframe-v1","ModuleParameters":[{"Name":"title","Value":"全国疫情趋势-增长趋势","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"line","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"x","Value":"日期","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"疑似增长,确诊增长","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"options","Value":"{\n 'chart': {\n 'height': 500\n }\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"candlestick","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_1","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_2","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_3","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_4","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-206"}],"OutputPortsInternal":[],"UsePreviousResults":false,"moduleIdForCode":7,"IsPartOfPartialRun":null,"Comment":"全国疫情趋势-增长","CommentCollapsed":false},{"Id":"-107","ModuleId":"BigQuantSpace.cached.cached-v3","ModuleParameters":[{"Name":"run","Value":"def bigquant_run(input_1, input_2, input_3):\n df = input_1.read()[['日期', '省份', '疑似', '确诊', '治愈', '死亡']]\n\n none_hubei = df[df['省份'] != 'hubei'].groupby('日期')[['疑似', '确诊', '治愈', '死亡']].sum().reset_index()\n none_hubei['省份'] = '非湖北'\n\n df = pd.concat([df, none_hubei], ignore_index=True)\n\n province_names = {\n 'beijing': '北京',\n 'shanghai': '上海',\n 'tianjin': '天津',\n 'chongqing': '重庆',\n 'xianggang': '香港',\n 'aomen': '澳门',\n 'anhui': '安徽',\n 'fujian': '福建',\n 'guangdong': '广东',\n 'guangxi': '广西',\n 'guizhou': '贵州',\n 'gansu': '甘肃',\n 'hainan': '海南',\n 'hebei': '河北',\n 'henan': '河南',\n 'heilongjiang': '黑龙江',\n 'hubei': '湖北',\n 'hunan': '湖南',\n 'jilin': '吉林',\n 'jiangsu': '江苏',\n 'jiangxi': '江西',\n 'liaoning': '辽宁',\n 'neimenggu': '内蒙古',\n 'ningxia': '宁夏',\n 'qinghai': '青海',\n 'shanxis': '陕西',\n 'shanxi': '山西',\n 'shandong': '山东',\n 'sichuan': '四川',\n 'taiwan': '台湾',\n 'xizang': '西藏',\n 'xinjiang': '新疆',\n 'yunnan': '云南',\n 'zhejiang': '浙江',\n '非湖北': '非湖北',\n }\n df['省份'] = df['省份'].apply(lambda x: province_names[x])\n\n province_df = df.pivot_table(values='确诊', index='日期', columns='省份')\n\n hubei_df = province_df[province_df.columns[province_df.columns.isin({'湖北', '非湖北'})]]\n # hubei_df['湖北增长率'] = hubei_df['湖北'] / hubei_df['湖北'].shift(1) - 1\n # hubei_df['非湖北增长率'] = hubei_df['非湖北'] / hubei_df['非湖北'].shift(1) - 1\n others_df = province_df[province_df.columns[~province_df.columns.isin({'湖北', '非湖北'})]]\n \n data_1 = DataSource.write_df(hubei_df)\n data_2 = DataSource.write_df(others_df)\n return Outputs(data_1=data_1, data_2=data_2)\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"post_run","Value":"# 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。\ndef bigquant_run(outputs):\n return outputs\n","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"input_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"params","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"output_ports","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_1","NodeId":"-107"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_2","NodeId":"-107"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_3","NodeId":"-107"}],"OutputPortsInternal":[{"Name":"data_1","NodeId":"-107","OutputType":null},{"Name":"data_2","NodeId":"-107","OutputType":null},{"Name":"data_3","NodeId":"-107","OutputType":null}],"UsePreviousResults":false,"moduleIdForCode":9,"IsPartOfPartialRun":null,"Comment":"","CommentCollapsed":true},{"Id":"-126","ModuleId":"BigQuantSpace.plot_dataframe.plot_dataframe-v1","ModuleParameters":[{"Name":"title","Value":"全国疫情趋势-治愈/重症/死亡率","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"line","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"x","Value":"日期","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"重症率,治愈率,死亡率","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"options","Value":"{\n 'chart': {\n 'height': 500\n }\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"candlestick","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_1","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_2","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_3","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_4","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-126"}],"OutputPortsInternal":[],"UsePreviousResults":false,"moduleIdForCode":8,"IsPartOfPartialRun":null,"Comment":"全国疫情趋势-治愈/重症/死亡率","CommentCollapsed":false},{"Id":"-78","ModuleId":"BigQuantSpace.plot_dataframe.plot_dataframe-v1","ModuleParameters":[{"Name":"title","Value":"全国疫情趋势-增长率趋势","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"line","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"x","Value":"日期","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"疑似增长率,确诊增长率","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"options","Value":"{\n 'chart': {\n 'height': 500\n }\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"candlestick","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_1","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_2","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_3","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_4","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-78"}],"OutputPortsInternal":[],"UsePreviousResults":false,"moduleIdForCode":10,"IsPartOfPartialRun":null,"Comment":"全国疫情趋势-增长率","CommentCollapsed":false},{"Id":"-90","ModuleId":"BigQuantSpace.plot_dataframe.plot_dataframe-v1","ModuleParameters":[{"Name":"title","Value":"湖北/非湖北疫情趋势-确诊","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"line","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"x","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"options","Value":"{\n 'chart': {\n 'height': 500\n }\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"candlestick","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_1","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_2","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_3","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_4","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-90"}],"OutputPortsInternal":[],"UsePreviousResults":false,"moduleIdForCode":11,"IsPartOfPartialRun":null,"Comment":"湖北,非湖北","CommentCollapsed":false},{"Id":"-114","ModuleId":"BigQuantSpace.plot_dataframe.plot_dataframe-v1","ModuleParameters":[{"Name":"title","Value":"各省(除湖北外)疫情趋势-确诊","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"chart_type","Value":"line","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"x","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"y","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"options","Value":"{\n 'chart': {\n 'height': 500\n }\n}","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"candlestick","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_1","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_2","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_3","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"pane_4","Value":"","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-114"}],"OutputPortsInternal":[],"UsePreviousResults":false,"moduleIdForCode":12,"IsPartOfPartialRun":null,"Comment":"各省(除湖北外)疫情趋势","CommentCollapsed":false}],"SerializedClientData":"<?xml version='1.0' encoding='utf-16'?><DataV1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><Meta /><NodePositions><NodePosition Node='-25' Position='167,6,200,200'/><NodePosition Node='-32' Position='353,221,200,200'/><NodePosition Node='-36' Position='-76,431,200,200'/><NodePosition Node='-55' Position='356,117,200,200'/><NodePosition Node='-63' Position='481,7,200,200'/><NodePosition Node='-66' Position='-85,538,200,200'/><NodePosition Node='-206' Position='264,384,200,200'/><NodePosition Node='-107' Position='630,356,200,200'/><NodePosition Node='-126' Position='266,571,200,200'/><NodePosition Node='-78' Position='264,478,200,200'/><NodePosition Node='-90' Position='630,441,200,200'/><NodePosition Node='-114' Position='631,546,200,200'/></NodePositions><NodeGroups /></DataV1>"},"IsDraft":true,"ParentExperimentId":null,"WebService":{"IsWebServiceExperiment":false,"Inputs":[],"Outputs":[],"Parameters":[{"Name":"交易日期","Value":"","ParameterDefinition":{"Name":"交易日期","FriendlyName":"交易日期","DefaultValue":"","ParameterType":"String","HasDefaultValue":true,"IsOptional":true,"ParameterRules":[],"HasRules":false,"MarkupType":0,"CredentialDescriptor":null}}],"WebServiceGroupId":null,"SerializedClientData":"<?xml version='1.0' encoding='utf-16'?><DataV1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><Meta /><NodePositions></NodePositions><NodeGroups /></DataV1>"},"DisableNodesUpdate":false,"Category":"user","Tags":[],"IsPartialRun":true}
    In [1]:
    # 本代码由可视化策略环境自动生成 2020年2月7日 11:20
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    def m9_run_bigquant_run(input_1, input_2, input_3):
        df = input_1.read()[['日期', '省份', '疑似', '确诊', '治愈', '死亡']]
    
        none_hubei = df[df['省份'] != 'hubei'].groupby('日期')[['疑似', '确诊', '治愈', '死亡']].sum().reset_index()
        none_hubei['省份'] = '非湖北'
    
        df = pd.concat([df, none_hubei], ignore_index=True)
    
        province_names = {
            'beijing': '北京',
            'shanghai': '上海',
            'tianjin': '天津',
            'chongqing': '重庆',
            'xianggang': '香港',
            'aomen': '澳门',
            'anhui': '安徽',
            'fujian': '福建',
            'guangdong': '广东',
            'guangxi': '广西',
            'guizhou': '贵州',
            'gansu': '甘肃',
            'hainan': '海南',
            'hebei': '河北',
            'henan': '河南',
            'heilongjiang': '黑龙江',
            'hubei': '湖北',
            'hunan': '湖南',
            'jilin': '吉林',
            'jiangsu': '江苏',
            'jiangxi': '江西',
            'liaoning': '辽宁',
            'neimenggu': '内蒙古',
            'ningxia': '宁夏',
            'qinghai': '青海',
            'shanxis': '陕西',
            'shanxi': '山西',
            'shandong': '山东',
            'sichuan': '四川',
            'taiwan': '台湾',
            'xizang': '西藏',
            'xinjiang': '新疆',
            'yunnan': '云南',
            'zhejiang': '浙江',
            '非湖北': '非湖北',
        }
        df['省份'] = df['省份'].apply(lambda x: province_names[x])
    
        province_df = df.pivot_table(values='确诊', index='日期', columns='省份')
    
        hubei_df = province_df[province_df.columns[province_df.columns.isin({'湖北', '非湖北'})]]
        # hubei_df['湖北增长率'] = hubei_df['湖北'] / hubei_df['湖北'].shift(1) - 1
        # hubei_df['非湖北增长率'] = hubei_df['非湖北'] / hubei_df['非湖北'].shift(1) - 1
        others_df = province_df[province_df.columns[~province_df.columns.isin({'湖北', '非湖北'})]]
        
        data_1 = DataSource.write_df(hubei_df)
        data_2 = DataSource.write_df(others_df)
        return Outputs(data_1=data_1, data_2=data_2)
    
    # 后处理函数,可选。输入是主函数的输出,可以在这里对数据做处理,或者返回更友好的outputs数据格式。此函数输出不会被缓存。
    def m9_post_run_bigquant_run(outputs):
        return outputs
    
    
    m1 = M.use_datasource.v1(
        datasource_id='bigquant-ncov2019',
        start_date='',
        end_date='',
        m_cached=False
    )
    
    m5 = M.input_features.v1(
        features="""instrument=province
    
    日期=date
    国家=country
    省份=province
    疑似=sus_num
    确诊=con_num
    重症=crit_num
    死亡=death_num
    治愈=cure_num
    密切接触=cont_num
    医学观察=obse_num
    疑似增长=sus_num - shift(sus_num, 1)
    确诊增长=con_num - shift(con_num, 1)
    疑似增长率=sus_num/shift(sus_num, 1) - 1
    确诊增长率=con_num/shift(con_num, 1) - 1
    死亡率=死亡/确诊
    重症率=重症/确诊
    治愈率=治愈/确诊
    """
    )
    
    m4 = M.derived_feature_extractor.v3(
        input_data=m1.data,
        features=m5.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={},
        m_cached=False
    )
    
    m2 = M.filter.v3(
        input_data=m4.data,
        expr='province == country',
        output_left_data=True,
        m_cached=False
    )
    
    m3 = M.plot_dataframe.v1(
        input_data=m2.data,
        title='全国疫情趋势',
        chart_type='line',
        x='日期',
        y='确诊,重症,死亡,治愈,疑似',
        options={
        'chart': {
            'height': 500
        }
    },
        candlestick=False,
        pane_1='',
        pane_2='',
        pane_3='',
        pane_4=''
    )
    
    m6 = M.plot_dataframe.v1(
        input_data=m2.data,
        title='全国疫情趋势-密切接触者跟踪',
        chart_type='line',
        x='日期',
        y='密切接触,医学观察',
        options={
        'chart': {
            'height': 500
        }
    },
        candlestick=False,
        pane_1='',
        pane_2='',
        pane_3='',
        pane_4=''
    )
    
    m7 = M.plot_dataframe.v1(
        input_data=m2.data,
        title='全国疫情趋势-增长趋势',
        chart_type='line',
        x='日期',
        y='疑似增长,确诊增长',
        options={
        'chart': {
            'height': 500
        }
    },
        candlestick=False,
        pane_1='',
        pane_2='',
        pane_3='',
        pane_4=''
    )
    
    m10 = M.plot_dataframe.v1(
        input_data=m2.data,
        title='全国疫情趋势-增长率趋势',
        chart_type='line',
        x='日期',
        y='疑似增长率,确诊增长率',
        options={
        'chart': {
            'height': 500
        }
    },
        candlestick=False,
        pane_1='',
        pane_2='',
        pane_3='',
        pane_4=''
    )
    
    m8 = M.plot_dataframe.v1(
        input_data=m2.data,
        title='全国疫情趋势-治愈/重症/死亡率',
        chart_type='line',
        x='日期',
        y='重症率,治愈率,死亡率',
        options={
        'chart': {
            'height': 500
        }
    },
        candlestick=False,
        pane_1='',
        pane_2='',
        pane_3='',
        pane_4=''
    )
    
    m9 = M.cached.v3(
        input_1=m2.left_data,
        run=m9_run_bigquant_run,
        post_run=m9_post_run_bigquant_run,
        input_ports='',
        params='{}',
        output_ports='',
        m_cached=False
    )
    
    m11 = M.plot_dataframe.v1(
        input_data=m9.data_1,
        title='湖北/非湖北疫情趋势-确诊',
        chart_type='line',
        x='',
        y='',
        options={
        'chart': {
            'height': 500
        }
    },
        candlestick=False,
        pane_1='',
        pane_2='',
        pane_3='',
        pane_4=''
    )
    
    m12 = M.plot_dataframe.v1(
        input_data=m9.data_2,
        title='各省(除湖北外)疫情趋势-确诊',
        chart_type='line',
        x='',
        y='',
        options={
        'chart': {
            'height': 500
        }
    },
        candlestick=False,
        pane_1='',
        pane_2='',
        pane_3='',
        pane_4=''
    )
    

    本文对新型冠状病毒2019-nCoV数据利用表达式引擎功能构建相关统计量,对武汉疫情发展趋势进行了数据可视化分析,我们将每日更新数据密切追踪疫情发展动向。


    (gguaiker) #2

    厉害了。。。还能这样用平台


    (大胡子) #3

    厉害了,不过,这是已经更新好数据到平台分析,请问我如何每天自己更新该数据呢?是否有例子,比如我需要每天更新新浪、东方财富网站上一些数据加入模型训练、策略开发。