Skip to content
This repository was archived by the owner on Aug 13, 2026. It is now read-only.
This repository was archived by the owner on Aug 13, 2026. It is now read-only.

extracting latitude from a string #126

Closed

Description

@arunaskuciauskas

To report a non-security related issue, please provide:

  • the version of the software with which you are encountering an issue
  • environmental information (i.e. Operating System, compiler info, java version, python version, etc.)
  • a description of the issue with the steps needed to reproduce it

If you have a general question about the software, please view our Suggested Support Process.

Activity

  1. arunaskuciauskas commented on Jan 28, 2022

    @arunaskuciauskas
    Author

    Hi: I am trying to extract the latitude from hundreds of files that contain the following listing:

    %TITLE%
    STC 190313/034000 -0.1,-27.46
    
           LEVEL       HGHT       TEMP       DWPT       WDIR       WSPD
    -------------------------------------------------------------------
    %RAW%
         1011.44,      0.00,     30.37,     24.46,      9.60,      0.01
          986.07,    227.06,     27.65,     22.99,      9.50,      0.01
          958.59,    477.68,     25.43,     21.13,      9.40,      0.01
          931.52,    730.00,     23.50,     19.20,      9.30,      0.01
    

    I perform the following read:
    df = pd.read_csv(fn, sep ='s,', skiprows=0, nrows = 1)

    resulting in output:

    %TITLE%
    0  STC 190313/034000 -0.36,-25.61
    

    where the latitude is -0.36, my intended value. In reading multiple files, the latitude value in the files can vary
    in format from 0.0 (2 char), to -25.67 (6 char)

    I applied a split on the '/' as:

        coord = df.iloc[0,0]
        print('Coord ',coord)

    resulting in output:

    Coord:  STC 190313/034000 -0.36,-25.61
    
    lat = coord.split('/')
    lati = lat[1][7:12]
    print('lati: ', lati)

    resulting in output:
    lati: -0.1,

    The start of the latitude value always starts in the 7th position
    Question: How can I make sure that I grab the entire latitude value?

  2. dopplershift commented on Feb 19, 2022

    @dopplershift
    Member

    Apologies for the delayed response. I wouldn't use parse_csv to handle any of that header, only the later data. This is what I wrote to parse what you provided:

    with open(fn, 'rt') as infile:
        # skip "%TITLE%
        infile.readline()
    
        # Get the siteid, date string, and lat/lon group by splitting on whitespace
        site, date, latlon = infile.readline().split()
    
        # Split the lat/lon group on a comma and convert to floats
        lat, lon = map(float, latlon.split(','))
    
        # Skip blank
        infile.readline()
    
        # Get the column names from the names that *don't* have commas
        columns = infile.readline().split()
    
        # Let pandas parse the rest of the file
        df = pd.read_csv(infile, skiprows=2, names=columns)
  3. locked and limited conversation to collaborators on Feb 22, 2022
  4. converted this issue into a discussion #129 on Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions