Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 948575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:15:57+00:00 2026-05-15T23:15:57+00:00

I need to process weather station data which is in a format like this

  • 0

I need to process weather station data which is in a format like this (SYNOP), where each line represents one measurement and I have thousands of measurements:

line = 'AAXX 01004 60265 32970 03404 10048 20010 38997 48605 51014='

Starting with the 6th block, the blocks are numbered (1xxxx 2xxxx 3xxxx etc, sometimes only 5 blocks but sometimes also more with additional data)

The crucial point is that the number of blocks between the AAXX and the 1xxxx block is not always the same, but I know that 2 blocks before the 1xxxx block there is data I need. To reliably pinpoint that block I would need to determine the position of the 1xxxx block and count backwards from there.

My idea is to split the line along spaces into a list, and then iterate through the list items to find the position in the list of the 1xxxx block.

list = line.split(' ')

But I don’t know how to do this iteration. There must be a reasonably elegant way to look for 3 blocks where the first starts with 1, the second with 2, and the third with 3, then return the list index of the first block?

This may be very simple but I’m unable to figure it out, and would be grateful for any tips!

EDIT: To clarify, it’s possible that another block starting with 1 appears before the one I need, so the only reliable way to pinpoint the block I need is to ensure that it is followed by one that starts with 2 and another that starts with 3 (that should reduce the chance of a false positive to pretty much 0).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T23:15:57+00:00Added an answer on May 15, 2026 at 11:15 pm

    There is more than one way to do this. One way would be to search the list for the index and subtract two:

    list[ (i for i, j in enumerate( list ) if j.startswith( "1" ) ).next() - 2 ]
    

    Another way would be to match a regex onto the (unsplit) string:

    import re
    re.search( "\d{5}(?= \d{5} 1\d{4} 2\d{4} 3\d{4})", line )
    

    This matches a block of five digits, as long as it’s followed by 1xxxx 2xxxx 3xxxx where x is any digit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.