data_processing/prepare_dataset_for_datavis.py
def prepare_dataset(
    infile=DATA_FROM_SPREADSHEET,
    lookup=GEO_LOOKUP,
    outfile=OUTFILE):
    """
    Get the data from the Google Spreadsheet, add current location name, latitude,
    longitude and URLs.
    """

    # Create geo dict
    df_lookup = pd.read_csv(lookup)
    all_lat = list(df_lookup['latitude'])
    all_long = list(df_lookup['longitude'])
    all_borough_name = list(df_lookup['borough name'])

    geodict = {}
    for i in range(len(all_lat)):
        geodict[all_borough_name[i]] = {
            'latitude': all_lat[i],
            'longitude': all_long[i]
        }

    # Add location
    df = pd.read_csv(infile)
    all_current_boroughs = list(df['location_current'].values)

    latitude_list = []
    longitude_list =[]
    for x in all_current_boroughs:
        if x in geodict.keys():
            latitude = geodict[x]['latitude']
            longitude = geodict[x]['longitude']
            latitude_list.append(latitude)
            longitude_list.append(longitude)
        else:
            latitude_list.append(0)
            longitude_list.append(0)

    df['location_latitude'] = latitude_list
    df['location_longitude'] = longitude_list

    df = df.fillna(0)

    # Add Moh place
    df_moh_places = pd.read_csv(GEO_LOOKUP_MOH)
    print df_moh_places

    # Add URL
    list_of_bNumbers = list(df['source_bNumber'].values)
    list_of_urls = ['http://wellcomelibrary.org/item/' + x for x in list_of_bNumbers]
    df['source_url'] = list_of_urls

    df.to_csv(outfile, index=None)

    Get the data from the Google Spreadsheet, add current location name, latitude,
    longitude and URLs.
    
Get the data from the Google Spreadsheet, add current location name, latitude,
longitude and URLs.
Get the data from the Google Spreadsheet add current location name latitude longitude and URLs .
def prepare_dataset(
    infile=DATA_FROM_SPREADSHEET,
    lookup=GEO_LOOKUP,
    outfile=OUTFILE):
    df_lookup = pd.read_csv(lookup)
    all_lat = list(df_lookup['latitude'])
    all_long = list(df_lookup['longitude'])
    all_borough_name = list(df_lookup['borough name'])
    geodict = {}
    for i in range(len(all_lat)):
        geodict[all_borough_name[i]] = {
            'latitude': all_lat[i],
            'longitude': all_long[i]
        }
    df = pd.read_csv(infile)
    all_current_boroughs = list(df['location_current'].values)
    latitude_list = []
    longitude_list =[]
    for x in all_current_boroughs:
        if x in geodict.keys():
            latitude = geodict[x]['latitude']
            longitude = geodict[x]['longitude']
            latitude_list.append(latitude)
            longitude_list.append(longitude)
        else:
            latitude_list.append(0)
            longitude_list.append(0)
    df['location_latitude'] = latitude_list
    df['location_longitude'] = longitude_list
    df = df.fillna(0)
    df_moh_places = pd.read_csv(GEO_LOOKUP_MOH)
    print df_moh_places
    list_of_bNumbers = list(df['source_bNumber'].values)
    list_of_urls = ['http://wellcomelibrary.org/item/' + x for x in list_of_bNumbers]
    df['source_url'] = list_of_urls
    df.to_csv(outfile, index=None)
def prepare_dataset ( infile = DATA_FROM_SPREADSHEET , lookup = GEO_LOOKUP , outfile = OUTFILE ) : df_lookup = pd . read_csv ( lookup ) all_lat = list ( df_lookup [ 'latitude' ] ) all_long = list ( df_lookup [ 'longitude' ] ) all_borough_name = list ( df_lookup [ 'borough name' ] ) geodict = { } for i in range ( len ( all_lat ) ) : geodict [ all_borough_name [ i ] ] = { 'latitude' : all_lat [ i ] , 'longitude' : all_long [ i ] } df = pd . read_csv ( infile ) all_current_boroughs = list ( df [ 'location_current' ] . values ) latitude_list = [ ] longitude_list = [ ] for x in all_current_boroughs : if x in geodict . keys ( ) : latitude = geodict [ x ] [ 'latitude' ] longitude = geodict [ x ] [ 'longitude' ] latitude_list . append ( latitude ) longitude_list . append ( longitude ) else : latitude_list . append ( 0 ) longitude_list . append ( 0 ) df [ 'location_latitude' ] = latitude_list df [ 'location_longitude' ] = longitude_list df = df . fillna ( 0 ) df_moh_places = pd . read_csv ( GEO_LOOKUP_MOH ) print df_moh_places list_of_bNumbers = list ( df [ 'source_bNumber' ] . values ) list_of_urls = [ 'http://wellcomelibrary.org/item/' + x for x in list_of_bNumbers ] df [ 'source_url' ] = list_of_urls df . to_csv ( outfile , index = None )
Get the data from the Google Spreadsheet, add current location name, latitude,
longitude and URLs.
Get the data from the Google Spreadsheet add current location name latitude longitude and URLs .
"""
    Get the data from the Google Spreadsheet, add current location name, latitude,
    longitude and URLs.
    """ # Create geo dict # Add location # Add Moh place # Add URL
infile
lookup
outfile