Hi Guys,
I have text file having two columns: 1) column 1 is in the format yyyy-mm-dd and 2) column 2 is precipitation.
Objective: to extract original value of precipitation from column 2 only for month April, May, june, July, and August (4,5,6,7,8).
Procedure: Used line.split to extract only mm from yyyy-mm-dd format from column-1.
Problem: I can successfully print k,v (month and precipitation) from dictionary items. However, when I am using a if statement to extract the specific month's precipitation value, I am getting blank array. I was wondering can I use .append to get precipitation in (1.8,2.1,3.3)
format.
Code:
file1 = open("test.txt","r") Growing=[] Intermediate=[] Dormant=[] for line in file1: line2 = line.split() WQ = line2[1] month = line2[0].split("-")[1] dct1={month:WQ} for k,v in dct1.items(): if (k ==4 or k==5 or k==6 or k==7 or k==8): Growing.append(dct1) print Growing
Solved! Go to Solution.
Thanks a lot! I really appreciate it! Have a good one.
Sean
You´re welcome