generate_data_map.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:Smelly-London 作者: Smelly-London 项目源码 文件源码
def create_carto_file():
    """ Creates a .csv file to be uploaded into http://carto.com with the smells. """

    location_finder = LocationFinder()

    filename = "carto.csv"
    csv_file = open(filename, "w", newline="")
    print("Output file: {}".format(filename))

    map_writer = csv.writer(csv_file, delimiter=",", quoting=csv.QUOTE_ALL)

    map_writer.writerow(["longitude", "latitude", "date", "location_name", "number_of_smells"])

    missing_locations = []
    for borough_name, borough_information in smell_hits.res.items():
        for year, number_of_smells in borough_information.items():
            (latitude, longitude) = location_finder.lookup(borough_name)
            if latitude is not None and longitude is not None:
                date = "{}/01/01".format(year)
                map_writer.writerow([latitude, longitude, date, borough_name, number_of_smells])
            else:
                if borough_name not in missing_locations:
                    missing_locations.append(borough_name)

    print("Missing locations:", missing_locations)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号