def MakeList_column(filename): Row_List = MakeList(filename) # print(Row_List) Col_List = [] for j in range(len(Row_List[0])): Temp_List = [] for i in range(len(Row_List)): # print(i) Temp_List.append(Row_List[i][j]) Col_List.append(Temp_List) # print(Col_List) return Col_List
def Add_first(texts_path): Total_data_list = [] all_text_path = texts_path print("Total involved text data files :", len(all_text_path)) #print(read_file_name(all_text_path[0])) for i in range(len(all_text_path)): print(all_text_path[i]) First_col_write = read_file_name(all_text_path[i])[0] #print(First_col_write) ROW_LIST = MakeList(read_file_name(all_text_path[i])[2]) for j in range(len(ROW_LIST)): if ROW_LIST[j][0] == " ": continue if ROW_LIST[j][0] == "V1": continue temp_list = [First_col_write] for k in range(len(ROW_LIST[j])): temp_list.append(ROW_LIST[j][k]) Total_data_list.append(temp_list) #print(Total_data_list) print("Total Entry :", len(Total_data_list)) return Total_data_list
def ADD_daily_date_FirstLine(START_YEAR=1996, START_MONTH=1, START_DAY=1, infilename="daily_test.txt"): filename_list = read_file_name(infilename) infile = filename_list[2] outfile = infile outfile = outfile.replace(".txt", "") outfile = outfile + "_Daily.txt" year = START_YEAR month = START_MONTH day = START_DAY DATE_class = DATE_MAKER() Daily_date_list = [] Daily_date_list.append("DATE") for i in range(10000): # for i in range(8036): DATE_num = DATE_class.DATE_MAKER(year, month, day) DATE_str = DATE_class.MAKE_DATE_STR(DATE_num) # print(DATE_str[3]) Daily_date_list.append(DATE_str[3]) year = DATE_num[0] month = DATE_num[1] day = DATE_num[2] + 1 Origin_row_list = MakeList(infile) # print(Origin_row_list) return_list = [] for i in range(len(Origin_row_list)): temp_list = [] temp_list.append(Daily_date_list[i]) for j in range(len(Origin_row_list[0])): temp_list.append(Origin_row_list[i][j]) return_list.append(temp_list) MAKE_TXT(return_list, outfile) # print(return_list) print("created file name : ", outfile) return outfile
import sys sys.path.append( "/Users/leejunho/Desktop/git/python3Env/group_study/project_pre/func") from d0_makelist import MakeList #infile = "/Users/leejunho/Desktop/git/python3Env/group_study/project_pre/data_txt/BEIJING_Aqi/Aqi_Beijing_day.txt" infile = "/Users/leejunho/Desktop/git/python3Env/group_study/project_pre/data_txt/BEIJING_Aqi/carbon_copied_data/Aqi_Beijing_HOLI_byej.txt" CLIST = MakeList(infile) LEN = len(CLIST) clen = len(CLIST[0]) print(CLIST) print("Total Line Number of input file :", LEN) print("For each line, should be ", clen, "lines.") for i in range(len(CLIST)): if (clen != len(CLIST[i])): print("!!! On", i, "th line number, NOT EQUAL COLUMNS, ERROR !!!") break else: if (i == 0): continue else: for j in range(len(CLIST[i])): try: temp = float(CLIST[i][j]) except: ValueError print(i) break
import sys, os sys.path.append("/Users/leejunho/Desktop/git/python3Env/group_study/project_pre/func") from d0_makelist import MakeList ROW_list = MakeList("Expand.txt") Expand_Row_list = [] for EX in range(100): for i in range(len(ROW_list)): if(i==0): if(EX==0): Expand_Row_list.append(ROW_list[i]) continue else: continue Expand_Row_list.append(ROW_list[i]) #print(Expand_Row_list) Of = open("Expand_multi10.txt", "w+") for i in range(len(Expand_Row_list)): for j in range(len(Expand_Row_list[i])): Of.write("%s" %Expand_Row_list[i][j]) if(j!=len(Expand_Row_list[i])-1): Of.write(" ") if(j==len(Expand_Row_list[i])-1): Of.write("\n") Of.close()
import sys import os sys.path.append("../func") from d0_makelist import MakeList #filename = ("../data_txt/ALL_DATA/Aqi_Beijing_monthly.txt") filename = ("../data_txt/ALL_DATA/Aqi_Beijing_WIND.txt") list_A = MakeList(filename) import scipy.stats as stats ''' a=[28,24,22,23,28] b=[24,22,28,22,24] c=[21,20,21,23,20] ANOVA = stats.f_oneway(a,b,c) print(ANOVA) ''' #print(list_A) Y2014 = [] Y2015 = [] Y2016 = [] Y2017 = [] Y2018 = [] year = 201400 print(list_A[0]) for ii in range(len(list_A)): if ii == 0: continue elif float(list_A[ii][0]) < 20140000: continue
def MakeMonthlyDate_BaseOnDailyDate(infilename="test.txt"): filename_list = read_file_name(infilename) infile = filename_list[2] outfile = infile outfile = outfile.replace(".txt", "") outfile = outfile.replace("_Daily", "") outfile = outfile + "_Monthly.txt" row_list = MakeList(infile) return_list = [] return_list.append(row_list[0]) refresh_date_flag = 1 for i in range(len(row_list)): temp_list = [] if (i == 0): continue if ((i == 1) | (refresh_date_flag == 0)): first_list = [] iterated_num = 1 month_date = row_list[i][0][:6] refresh_date_flag = 1 temp_list.append(month_date) for j in range((len(row_list[0]) - 1)): temp_list.append(row_list[i][j + 1]) first_list = temp_list # print(first_list) continue if (row_list[i][0][:6] == month_date): for j in range((len(row_list[0]))): if (j == 0): temp_list.append(row_list[i][0][:6]) else: calc = float(first_list[j]) + float(row_list[i][j]) #calc = "%0.3f"%calc; str_calc = str(calc) temp_list.append(calc) first_list = temp_list iterated_num = iterated_num + 1 # print(first_list) if ((i == len(row_list) - 1)): return_temp_list = [] for k in range(len(first_list)): if k == 0: return_temp_list.append(first_list[0]) else: calc = float(first_list[k]) / float(iterated_num) calc = "%0.4f" % calc str_calc = str(calc) return_temp_list.append(str_calc) return_list.append(return_temp_list) break if (row_list[i + 1][0][:6] != month_date): return_temp_list = [] refresh_date_flag = 0 for k in range(len(first_list)): if k == 0: return_temp_list.append(first_list[0]) else: calc = float(first_list[k]) / float(iterated_num) calc = "%0.4f" % calc str_calc = str(calc) return_temp_list.append(str_calc) return_list.append(return_temp_list) # print(return_list) MAKE_TXT(return_list, outfile) print("created file name : ", outfile) return outfile
def PICKING_BRANCH_n_SAVING(filename1): if (filename1[0] == "/"): filename1 = filename1 elif (filename1[0] == '~'): filename1 = filename1.replace("~", os.environ['HOME']) elif ((filename1[0] == "C") & (filename1[1] == ":")): filename1 = filename1 else: filename1 = os.getcwd( ) + "/" + filename1 # get the path included filename loca1 = len(filename1) for i in range(1, len(filename1) + 1): # find the "/" location if (filename1[-i] == "/"): loca1 = i - 1 break FILENAME1 = filename1.replace(filename1[:-loca1], "") # this is the shorten filename filename1_No_Txt = FILENAME1.replace(".txt", "") infile1 = filename1 print(infile1) RawList = MakeList(infile1) RawList_c = MakeList_column(infile1) num = 1 print("Which branch do you want to extract? (Press 'q' to stop slecting)") for j in RawList[0]: print(num, ":", j, "", end="\n") num = num + 1 #print("Please input branch name you want to extract") List_c = [] print("Please input Branch Name(not branch number)!") for i in range(len(RawList[0])): print("Branch Name (Press 'q' to stop slecting): ", end='') Branch_name = input() if Branch_name in RawList[0]: index_num = 0 for j in RawList[0]: if j == Branch_name: List_c.append(RawList_c[index_num]) #print(List_c) break else: index_num = index_num + 1 #print(index_num) elif Branch_name not in RawList[0] and Branch_name != "q": print("There are no such branches!") elif Branch_name == "q": break FN = infile1.replace(".txt", "_P.txt") Of = open(FN, "w+") for i in range(len(RawList)): for j in range(len(List_c)): Of.write("%s" % List_c[j][i]) if (j != len(List_c) - 1): Of.write(" ") if (j == len(List_c) - 1): Of.write("\n") Of.close() return FN
def make_monthly_data(filename): if (filename[0] == "/"): filename = filename else: filename = os.getcwd( ) + "/" + filename # get the path included filename loca = len(filename) for i in range(1, len(filename) + 1): # find the "/" location if (filename[-i] == "/"): loca = i - 1 break FILENAME = filename.replace(filename[:-loca], "") # this is the shorten filename filename_No_Txt = FILENAME.replace(".txt", "") infile = filename tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 SAVENAME = filename_No_Txt + "_monthly.txt" print(SAVENAME) f = open(SAVENAME, "w+") OLD_LIST = MakeList(infile) ################################## #### 2013 for i in range(len(OLD_LIST)): if (i == 0): f.write('DATE AQI PM2p5 PM10 SO2 CO NO2 O3_8h\n') continue # print(OLD_LIST[i][0]) if ((int(OLD_LIST[i][0]) > 20131200) & (int(OLD_LIST[i][0]) < 20140100)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20140100): # f.write("201312 %f %f %f %f %f %f %f" %(tempAqi/iterator) (tempAqi/iterator) ) f.write("201312 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 ################################## #### 2014 if ((int(OLD_LIST[i][0]) > 20140100) & (int(OLD_LIST[i][0]) < 20140200)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20140200): f.write("201401 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20140200) & (int(OLD_LIST[i][0]) < 20140300)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20140300): f.write("201402 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20140300) & (int(OLD_LIST[i][0]) < 20140400)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20140400): f.write("201403 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20140400) & (int(OLD_LIST[i][0]) < 20140500)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20140500): f.write("201404 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20140500) & (int(OLD_LIST[i][0]) < 20140600)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20140600): f.write("201405 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20140600) & (int(OLD_LIST[i][0]) < 20140700)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20140700): f.write("201406 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20140700) & (int(OLD_LIST[i][0]) < 20140800)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20140800): f.write("201407 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20140800) & (int(OLD_LIST[i][0]) < 20140900)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20140900): f.write("201408 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20140900) & (int(OLD_LIST[i][0]) < 20141000)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20141000): f.write("201409 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20141000) & (int(OLD_LIST[i][0]) < 20141100)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20141100): f.write("201410 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20141100) & (int(OLD_LIST[i][0]) < 20141200)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20141200): f.write("201411 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20141200) & (int(OLD_LIST[i][0]) < 20150100)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20150100): f.write("201412 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 ################################## #### 2015 if ((int(OLD_LIST[i][0]) > 20150100) & (int(OLD_LIST[i][0]) < 20150200)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20150200): f.write("201501 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20150200) & (int(OLD_LIST[i][0]) < 20150300)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20150300): f.write("201502 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20150300) & (int(OLD_LIST[i][0]) < 20150400)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20150400): f.write("201503 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20150400) & (int(OLD_LIST[i][0]) < 20150500)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20150500): f.write("201504 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20150500) & (int(OLD_LIST[i][0]) < 20150600)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20150600): f.write("201505 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20150600) & (int(OLD_LIST[i][0]) < 20150700)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20150700): f.write("201506 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20150700) & (int(OLD_LIST[i][0]) < 20150800)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20150800): f.write("201507 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20150800) & (int(OLD_LIST[i][0]) < 20150900)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20150900): f.write("201508 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20150900) & (int(OLD_LIST[i][0]) < 20151000)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20151000): f.write("201509 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20151000) & (int(OLD_LIST[i][0]) < 20151100)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20151100): f.write("201510 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20151100) & (int(OLD_LIST[i][0]) < 20151200)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20151200): # print(tempAqi, iterator) f.write("201511 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20151200) & (int(OLD_LIST[i][0]) < 20160100)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20160100): f.write("201512 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 ################################## #### 2016 if ((int(OLD_LIST[i][0]) > 20160100) & (int(OLD_LIST[i][0]) < 20160200)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20160200): f.write("201601 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20160200) & (int(OLD_LIST[i][0]) < 20160300)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20160300): f.write("201602 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20160300) & (int(OLD_LIST[i][0]) < 20160400)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20160400): f.write("201603 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20160400) & (int(OLD_LIST[i][0]) < 20160500)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20160500): f.write("201604 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20160500) & (int(OLD_LIST[i][0]) < 20160600)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20160600): f.write("201605 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20160600) & (int(OLD_LIST[i][0]) < 20160700)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20160700): f.write("201606 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20160700) & (int(OLD_LIST[i][0]) < 20160800)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20160800): f.write("201607 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20160800) & (int(OLD_LIST[i][0]) < 20160900)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20160900): f.write("201608 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20160900) & (int(OLD_LIST[i][0]) < 20161000)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20161000): f.write("201609 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20161000) & (int(OLD_LIST[i][0]) < 20161100)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20161100): f.write("201610 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20161100) & (int(OLD_LIST[i][0]) < 20161200)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20161200): f.write("201611 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20161200) & (int(OLD_LIST[i][0]) < 20170100)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20170100): f.write("201612 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 ################################## #### 2017 if ((int(OLD_LIST[i][0]) > 20170100) & (int(OLD_LIST[i][0]) < 20170200)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20170200): f.write("201701 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20170200) & (int(OLD_LIST[i][0]) < 20170300)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20170300): f.write("201702 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20170300) & (int(OLD_LIST[i][0]) < 20170400)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20170400): f.write("201703 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20170400) & (int(OLD_LIST[i][0]) < 20170500)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20170500): f.write("201704 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20170500) & (int(OLD_LIST[i][0]) < 20170600)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20170600): f.write("201705 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20170600) & (int(OLD_LIST[i][0]) < 20170700)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20170700): f.write("201706 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20170700) & (int(OLD_LIST[i][0]) < 20170800)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20170800): f.write("201707 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20170800) & (int(OLD_LIST[i][0]) < 20170900)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20170900): f.write("201708 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20170900) & (int(OLD_LIST[i][0]) < 20171000)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20171000): f.write("201709 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20171000) & (int(OLD_LIST[i][0]) < 20171100)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20171100): f.write("201710 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20171100) & (int(OLD_LIST[i][0]) < 20171200)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20171200): f.write("201711 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20171200) & (int(OLD_LIST[i][0]) < 20180100)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20180100): f.write("201712 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 ################################## #### 2018 if ((int(OLD_LIST[i][0]) > 20180100) & (int(OLD_LIST[i][0]) < 20180200)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20180200): f.write("201801 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 if ((int(OLD_LIST[i][0]) > 20180200) & (int(OLD_LIST[i][0]) < 20180300)): tempAqi = tempAqi + float(OLD_LIST[i][1]) pm2p5 = pm2p5 + float(OLD_LIST[i][2]) pm10 = pm10 + float(OLD_LIST[i][3]) so2 = so2 + float(OLD_LIST[i][4]) co = co + float(OLD_LIST[i][5]) no2 = no2 + float(OLD_LIST[i][6]) o3_8h = o3_8h + float(OLD_LIST[i][7]) iterator = iterator + 1 if (int(OLD_LIST[i + 1][0]) > 20180300): f.write("201802 %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f %0.1f" % ((tempAqi / iterator), (pm2p5 / iterator), (pm10 / iterator), (so2 / iterator), (co / iterator), (no2 / iterator), (o3_8h / iterator))) f.write("\n") tempAqi, pm2p5, pm10, so2, co, no2, o3_8h = 0, 0, 0, 0, 0, 0, 0 iterator = 0 '''
import sys import os sys.path.append("../func") from d0_makelist import MakeList #filename = ("../data_txt/ALL_DATA/Aqi_Beijing_monthly.txt") filename = ("../data_txt/ALL_DATA/Aqi_Beijing_WIND.txt") list_A = MakeList(filename) import scipy.stats as stats import pandas as pd from pandas import Series, DataFrame from statsmodels.stats.multicomp import pairwise_tukeyhsd for ii in range(len(list_A)): if ii == 0: continue elif float(list_A[ii][0]) < 20140000: continue elif 20140000 < float(list_A[ii][0]) < 20150000: # Y2014.append(list_A[ii]) list_A[ii].append(int(2014)) elif 20150000 < float(list_A[ii][0]) < 20160000: # Y2015.append(list_A[ii]) list_A[ii].append(int(2015)) elif 20160000 < float(list_A[ii][0]) < 20170000: # Y2016.append(list_A[ii]) list_A[ii].append(int(2016)) elif 20170000 < float(list_A[ii][0]) < 20180000: # Y2017.append(list_A[ii]) list_A[ii].append(int(2017)) elif 20180000 < float(list_A[ii][0]): # Y2018.append(list_A[ii])
def N_sigma_skimming(filename, N_Of_Sigma=5): if (filename[0] == "/"): filename = filename elif ((filename[0] == "C") & (filename[1] == ":")): filename = filename else: filename = os.getcwd( ) + "/" + filename # get the path included filename loca = len(filename) for i in range(1, len(filename) + 1): # find the "/" location if (filename[-i] == "/"): loca = i - 1 break FILENAME = filename.replace(filename[:-loca], "") # this is the shorten filename filename_No_Txt = FILENAME.replace(".txt", "") infile = filename ROW_list = MakeList(infile) COL_list = MakeList_column(infile) Mean_list = list() Std_list = list() # VAR_list = list() Name_list = list() for i in range(len(COL_list)): Name_list.append(COL_list[i][0]) Mean_list.append(d0_exclude_1_mean((COL_list[i]))) # VAR_list.append(d0_exclude_1_variance((COL_list[i]))) Std_list.append(d0_exclude_1_STD((COL_list[i]))) # print(Name_list) # print(Mean_list) ''' RE_COL_LIST = [] for i in range(len(COL_list)): if((COL_list[i][0] == DATE) | (COL_list[i][0] == HOLI) | (COL_list[i][0] == DAYS)): continue L_NSIGMA = Mean_list[i] - N_Of_Sigma*Std_list[i] H_NSIGMA = Mean_list[i] + N_Of_Sigma*Std_list[i] for j in range(len(COL_list[i])): ''' ttt = 0 RE_ROW_LIST = [] for i in range(len(ROW_list)): if (i == 0): RE_ROW_LIST.append(ROW_list[i]) continue for j in range(len(ROW_list[i])): if (((Name_list[j] == "DATE") | (Name_list[j] == "HOLI") | (Name_list[j] == "DAYS")) & (j != (len(ROW_list[i]) - 1))): continue L_NSIGMA = Mean_list[j] - N_Of_Sigma * Std_list[j] H_NSIGMA = Mean_list[j] + N_Of_Sigma * Std_list[j] # print(L_NSIGMA, H_NSIGMA) if ((j == (len(ROW_list[i]) - 1)) & ((Name_list[j] == "DATE") | (Name_list[j] == "HOLI") | (Name_list[j] == "DAYS"))): RE_ROW_LIST.append(ROW_list[i]) elif ((float(ROW_list[i][j]) > L_NSIGMA) & (float(ROW_list[i][j]) < H_NSIGMA)): if (j == (len(ROW_list[i]) - 1)): RE_ROW_LIST.append(ROW_list[i]) else: continue else: ttt = ttt + 1 break # print(ttt) # print(RE_ROW_LIST) FN = infile.replace(".txt", "S.txt") Of = open(FN, "w+") for i in range(len(RE_ROW_LIST)): for j in range(len(RE_ROW_LIST[i])): Of.write("%s" % RE_ROW_LIST[i][j]) if (j != len(RE_ROW_LIST[i]) - 1): Of.write(" ") if (j == len(RE_ROW_LIST[i]) - 1): Of.write("\n") Of.close() # print(FN) return FN