Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2024
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. import pandas as pd
  2.  
  3. def dms_to_decimal (dms):
  4.     #splitting the string data into separate degrees, minutes and seconds
  5.     dms_parts = dms.split('-')
  6.  
  7.     #Remove decimal point and numbers from Seconds data
  8.     seconds = dms_parts[-1].split('.')[0]
  9.     degrees, minutes = map(float, dms_parts[:-1])
  10.     #Converting to Decimal Degrees
  11.     decimal_degrees = degrees + (minutes / 60) + (seconds / 3600)
  12.     return decimal_degrees
  13.  
  14. #Loading the Excel file of the Turbine Data
  15. file_path = r'C:\Users\Me\Documents\Turbine_Coordinates.xlsx'
  16. df = pd.read_excel(file_path)
  17.  
  18. df['Latitude'] = df['Latitude'].str.replace('-', '', regex= False) #Removing the dashes from the Latitude column data
  19. df['Longitude'] = df['Longitude'].str.replace('-', '', regex= False) #Removing the dashes from the Longitude column data
  20.  
  21. #Converting from DMS to Decimal Degrees
  22. df['Latitude'] = df['Latitude'].apply(dms_to_decimal)
  23. df['Longitude'] = df['Longitude'].apply(dms_to_decimal)
  24.  
  25. #Save updated dataframe as new Excel file
  26. df.to_excel('Turbine_Locations_Converted.xlsx', index= False)
  27.  
  28. print(df)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement