In [1]:
%%file test.csv
30.263888889,45.563456
23.457654,34.433425
In [2]:
import pandas as pd
import numpy as np
In [3]:
input = pd.read_csv('test.csv', names=['Latitude', 'Longitude'])
input
Out[3]:
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]:
In [44]:
Lon
Out[44]:
In [45]:
s2d(Lat)
Out[45]:
In [46]:
s2d(Lon)
Out[46]:
In [ ]: