python - Regex to model the below mentioned type of expressions -


++++++++++++++++++++++++++++++++++++++++++++++++    | site | morning | afternoon | evening | night |   ++++++++++++++++++++++++++++++++++++++++++++++++   | long 144 - lat 18  | 100 | 150 | 10  | 5 |   ++++++++++++++++++++++++++++++++++++++++++++++++    | long 161 - lat 122 |   100   |   |   | 5 |   ++++++++++++++++++++++++++++++++++++++++++++++++   | long 100 - lat 134 |   100   |   | 5 |   |   ++++++++++++++++++++++++++++++++++++++++++++++++   | long 190 - lat 14  |    |    | 158 |  5  |   

since don't see pattern i'm stuck on how model regular expression extract values site, morning, afternoon, evening , night. example regex should able scrape ('long 144 - lat 18', '100','150','10','5') first row , ('long 161 - lat 122', '100','','','5') second row, on. i'm able scrape 'site' column can't think of model scrape rest. main thing don't have "|", "+" , "null" in data, used them here in question make little clear, replaced space in original data. appreciated. sorry ugly pattern, tried make pretty.
edit: data description pic here

the data in fixed-position format; that's easy handle.

you'll want read each line fully, , split line according column position. not regex or using .split().

e.g., simplistic version:

with open("data.txt") infile:     line in infile:          longitude = float(line[5:10])          latitude = float(line[15:20])          morning = line[25:30]          # see if there's data, otherwise assign default          morning = float(morning) if morning.strip() else 0          # ditto afternoon, evening, night 

the column limits chosen @ random in example; it'll easy figure them out correct data file.


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -