Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
new in this area
#1
Hello I am pretty new in this type of data anlysis so I am learning and tsting myself.

I have received thsi text in .pre format with precipitaions.

Teh document looks like this:

Output:
Tyndall Centre grim file created on 22.01.2004 at 17:57 by Dr. Tim Mitchell .pre = precipitation (mm) CRU TS 2.1 [Long=-180.00, 180.00] [Lati= -90.00, 90.00] [Grid X,Y= 720, 360] [Boxes= 67420] [Years=1991-2000] [Multi= 0.1000] [Missing=-999] Grid-ref= 1, 148 3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630 3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630 3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630 3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630 3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630 3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630 3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630 3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630 3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630 3020 2820 3040 2880 1740 1360 980 990 1410 1770 2580 2630 Grid-ref= 1, 311 490 290 280 230 200 250 440 530 460 420 530 450 490 290 280 230 200 250 440 530 460 420 530 450 490 290 280 230 200 250 440 530 460 420 530 450 490 290 280 230 200 250 440 530 460 420 530 450 490 290 280 230 200 250 440 530 460 420 530 450 490 290 280 230 200 250 440 530 460 420 530 450 490 290 280 230 200 250 440 530 460 420 530 450 490 290 280 230 200 250 440 530 460 420 530 450 490 290 280 230 200 250 440 530 460 420 530 450 490 290 280 230 200 250 440 530 460 420 530 450 Grid-ref= 1, 312 460 280 260 220 190 240 430 520 450 400 520 410 460 280 260 220 190 240 430 520 450 400 520 410 460 280 260 220 190 240 430 520 450 400 520 410 460 280 260 220 190 240 430 520 450 400 520 410 460 280 260 220 190 240 430 520 450 400 520 410 460 280 260 220 190 240 430 520 450 400 520 410 460 280 260 220 190 240 430 520 450 400 520 410 460 280 260 220 190 240 430 520 450 400 520 410 460 280 260 220 190 240 430 520 450 400 520 410 460 280 260 220 190 240 430 520 450 400 520 410
I have to extract teh data and export it into a table with this format:

Output:
Xref Yref Date Value 1 148 1/1/1991 3020 1 148 2/1/1991 2820
coming form the data previously attached. So each number within a row is corresponding to one month of a year and his value and each row is the data for each monthly value for a year.

I am pretty new so I would really appreciate if you can point me in some direction to get the result. I have read the document and tried to extract from each block from "grid-ref=" to the next "grid-ref=" to ride off of the beggining of the text. Unsuccessfully,

Thanks in advance
Reply
#2
Quote:I have read the document and tried to extract from each block
please post your attempt
Reply
#3
(Dec-31-2020, 04:14 PM)Larz60+ Wrote:
Quote:I have read the document and tried to extract from each block
please post your attempt

thanks for your answer I did this, the challenge I am trying to do is this link:

import csv
import os, sys
from itertools import islice
import re
import pandas as  pd
## sys.setdefaultencoding('utf-8')
 
table = []
 
csvfile = open('path_file','r')
datareader = csv.reader(csvfile)     ###   datareader = csv.reader(csvfile, delimiter=',')
for blocks in datareader:
    #print(blocks)   #### PRINTS Nested List  >> seperator = '' not ','
    #for i in blocks[0]:
        #print(i)
    for line in blocks:
        print(line)   ####  PRINTS the lines
 
## Prints the index, not the 
    ##for line in range(10):
        ##print(line)
     
 
df = pd.DataFrame(table)
##print(df)  #### Empty table
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020