Question: Python: I'm not sure how to further organize a list I've created. For this program, I am to draw the path of hurricane irma using
Python: I'm not sure how to further organize a list I've created.
For this program, I am to draw the path of hurricane irma using coordinates and wind speed found within a .csv file. With the code I provided below, I've managed to filter out the data to just the coordinates and wind speed as shown here:
>>>print(lines) [['16.4', '-30.3', '50'], ['16.4', '-31.2', '60'], ['16.4', '-32.2', '65']............
However, I need a way to further organize my list of 'lines' so that the first number of each set represents the x-value (latitude), the second number the y-value (longitude), and the third wind speed (not of much concern yet but I will need later on so it should be organized as well).
I'm not sure how to further chunk this list into usable coordinates and wind speed for which I could animate the path of the hurricane. Below is the code I have so far:
with open('irma.csv', 'r') as infile: # reading all file lines into variable 'lines' while stripping white space lines = [line.strip() for line in infile.readlines()] # removing headers from the file so lines only contains data lines = lines[1:] # separating data by each comma & indexing chunks into a list lines = [line.split(',') for line in lines] # filtering data to retain only the coordinates and wind speed lines = [line[2:5] for line in lines] Please help!
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
