Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pandas as pd
- def dms_to_decimal (dms):
- #splitting the string data into separate degrees, minutes and seconds
- dms_parts = dms.split('-')
- #Remove decimal point and numbers from Seconds data
- seconds = dms_parts[-1].split('.')[0]
- degrees, minutes = map(float, dms_parts[:-1])
- #Converting to Decimal Degrees
- decimal_degrees = degrees + (minutes / 60) + (seconds / 3600)
- return decimal_degrees
- #Loading the Excel file of the Turbine Data
- file_path = r'C:\Users\Me\Documents\Turbine_Coordinates.xlsx'
- df = pd.read_excel(file_path)
- df['Latitude'] = df['Latitude'].str.replace('-', '', regex= False) #Removing the dashes from the Latitude column data
- df['Longitude'] = df['Longitude'].str.replace('-', '', regex= False) #Removing the dashes from the Longitude column data
- #Converting from DMS to Decimal Degrees
- df['Latitude'] = df['Latitude'].apply(dms_to_decimal)
- df['Longitude'] = df['Longitude'].apply(dms_to_decimal)
- #Save updated dataframe as new Excel file
- df.to_excel('Turbine_Locations_Converted.xlsx', index= False)
- print(df)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement