Exemplo n.º 1
0
def get_p2p_overall_dataframe(dates=[yesterday()]):
    res = []
    for date in dates:
        print(date)
        for _, row in get_city_code_table().iterrows():
            history_curve = load_history(date, row.adcode)
            if history_curve is None:
                continue
            move_data = load_p2p(date, row.adcode)
            for record in move_data:
                from_city = row["name"]
                if from_city[-1] == "市":
                    from_city = from_city[:-1]

                to_city = record["city_name"]
                if to_city[-1] == "市":
                    to_city = to_city[:-1]

                to_province = record["province_name"]
                if to_province[-1] in ["省", "市"]:
                    to_province = to_province[:-1]

                new_entry = {
                    "m_date": pd.to_datetime(date),
                    "from_city": from_city,
                    "to_city": to_city,
                    "to_province": to_province,
                    "percentage": record["value"],
                    "migration_index": history_curve[date],
                }
                res.append(new_entry)
        time.sleep()
    return pd.DataFrame(res)
Exemplo n.º 2
0
def get_index_overall_dataframe(date=yesterday()):
    res = []
    for _, row in get_city_code_table().iterrows():
        history_curve = load_history(date, row.adcode)
        if history_curve is None:
            continue
        city = row["name"]
        if city[-1] in ["省", "市"]:
            city = city[:-1]
        for this_date in history_curve.keys():
            new_entry = {"m_date": pd.to_datetime(this_date), "city": city, "migration_index": history_curve[this_date]}
            res.append(new_entry)

    return pd.DataFrame(res)