In [1]:
%%file test.csv
30.263888889,45.563456
23.457654,34.433425


Overwriting test.csv

In [2]:
import pandas as pd
import numpy as np

In [3]:
input = pd.read_csv('test.csv', names=['Latitude', 'Longitude'])
input


Out[3]:
Latitude Longitude
0 30.263889 45.563456
1 23.457654 34.433425

In [49]:
def d2s(df,key='Latitude'):
    '''convert from decimal degrees to sessagesimal degrees
    take as input a pandas dataframe and a column name'''
    g = df[key].values.astype(int)
    p = ((( df[key].values) - df[key].values.astype(int))*60).astype(int)
    s = (((df[key].values - df[key].values.astype(int)) * 60. ) - p ) * 60.
    param = key
    ses = pd.DataFrame(np.array([g,p,s]).T, columns=['Degree','Minute','Second'] , dtype=float)
    return ses

def s2d(df,key=['Degree','Minute','Second']):
    '''convert from sessagesimal degrees to decimal degrees
    take as input a pandas dataframe and a list of column names'''
    deg=df[key[0]].values+(df[key[1]].values/60.+df[key[2]].values/3600.)
    return deg

In [39]:
Lat = d2s(df=input,key='Latitude')
Lon = d2s(df=input,key='Longitude')

In [40]:
Lat


Out[40]:
Degree Minute Second
0 30 15 50.0000
1 23 27 27.5544

In [44]:
Lon


Out[44]:
Degree Minute Second
0 45 33 48.4416
1 34 26 0.3300

In [45]:
s2d(Lat)


Out[45]:
array([ 30.26388889,  23.457654  ])

In [46]:
s2d(Lon)


Out[46]:
array([ 45.563456,  34.433425])

In [ ]: