Skip to content

extracting latitude from a string #129

Discussion options

You must be logged in to vote

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, s…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dcamron
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #126 on February 22, 2022 18:44.