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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -