python - Pandas Mapping Multiple Column Function on a DataFrame -
so have pandas dataframe containing column fields 'latitude' , 'longitude' , map function take 2 fields precision applied entire dataframe, , add column 'geohash' frame output of function being mapped.
right i've been able implement hackish string concatenation having mapped function parse out args appropriately. @ least shows output i'm looking for.
what have currently:
def my_encode(argstring): argstring = str.split(argstring,'_') lat,long,precision = float(argstring[0]),float(argstring[1]),int(argstring[2]) try: hash = geohash.encode(lat,long,precision) except: hash = '' return hash precision = 7 data['args'] = data['latitude'].astype(str) + '_' + data['longitude'].astype(str) + '_' + str(precision) data['hash'] = data['args'].map(my_encode)
its not terrible think more appropriate solution exists. in advance!
iiuc can way:
data['hash'] = data.apply(lambda x: geohash.encode(x.latitude, x.longitude, precision), axis=1)
Comments
Post a Comment