Feb-12-2021, 09:55 PM
(This post was last modified: Feb-12-2021, 09:55 PM by eddywinch82.)
Hi nilamo,
Here I have posted the Lines of Code, where I think the issue arises :-
in the DataFrame output ?
Regards
Eddie Winch
Here I have posted the Lines of Code, where I think the issue arises :-
for i,row in temp_df.iterrows(): text = row[0] date = row[1] month = row[2] if 'Lancaster' in text: temp_df.iat[i,3]='L' else: temp_df.iat[i,3]=None if 'Spitfire' in text: temp_df.iat[i,4]='S' elif 'S x 2' in text: temp_df.iat[i,4]='SS' elif 'S x 4' in text: temp_df.iat[i,4]='SSSS' else: temp_df.iat[i,4]=None if 'Hurricane' in text: temp_df.iat[i,5]='H' elif 'H x 2' in text: temp_df.iat[i,5]='HH' else: temp_df.iat[i,5]=None if 'Dakota' in text: temp_df.iat[i,6]='D' else: temp_df.iat[i,6]=None if '16' in date and 'Jun' in month: temp_df.iat[i,3]='L' temp_df.iat[i,4]='S' temp_df.iat[i,5]='H' elif '17' in date and 'Jun' in month: temp_df.iat[i,3]='--' temp_df.iat[i,4]='S' temp_df.iat[i,5]='H' if '13' in date and '15' in date and 'Royal' in text and 'Jul' in month: temp_df.iat[i,3]='L' temp_df.iat[i,4]='SS' temp_df.iat[i,5]='--' temp_df.iat[i,6]='D' elif '14' in date and 'Royal' in text and 'Jul' in month: temp_df.iat[i,3]='L' temp_df.iat[i,4]='SSS' temp_df.iat[i,5]='HH' temp_df.iat[i,6]='D' if '13' in date and 'Sep' in month: temp_df.iat[i,3]='L' temp_df.iat[i,4]='S' temp_df.iat[i,5]='H' for i,row in temp_df.iterrows(): text = row[1] text=text.replace('th','') text=text.replace('st','') text=text.replace('nd','') text=text.replace('rd','') temp_df.iat[i,1] = text for i,row in temp_df.iterrows(): date = row[1] month = row[2] location = row[0] if '-' in date: if month == 'May' and 'June' not in date: date_list = date.split("-") for j in range(int(date_list[0]),int(date_list[1])+1): dic = {"LOCATION":row[0],"DATE":str(j),"MONTH":row[2],"LANCASTER":row[3],"SPITFIRE":row[4],'HURRICANE':row[5],'DAKOTA':row[6]} temp_df=temp_df.append(dic, ignore_index = True) temp_df=temp_df.drop(temp_df[ temp_df['DATE'] == row[1] ].index) if month == 'May' and 'June' in date: date=date.replace(" June","") date_list = date.split("-") for j in range(int(date_list[0]),32): dic = {"LOCATION":row[0],"DATE":str(j),"MONTH":row[2],"LANCASTER":row[3],"SPITFIRE":row[4],'HURRICANE':row[5],'DAKOTA':row[6]} temp_df=temp_df.append(dic, ignore_index = True) for j in range(1,int(date_list[1])+1): dic = {"LOCATION":row[0],"DATE":str(j),"MONTH":'June',"LANCASTER":row[3],"SPITFIRE":row[4],'HURRICANE':row[5],'DAKOTA':row[6]} temp_df=temp_df.append(dic, ignore_index = True) temp_df=temp_df.drop(temp_df[ temp_df['DATE'] == row[1] ].index) if month == 'June' and 'July' not in date and 'Lancaster - SAT ONLY' not in row[0]: date_list = date.split("-") for j in range(int(date_list[0]),int(date_list[1])+1): dic = {"LOCATION":row[0],"DATE":str(j),"MONTH":row[2],"LANCASTER":row[3],"SPITFIRE":row[4],'HURRICANE':row[5],'DAKOTA':row[6]} temp_df=temp_df.append(dic, ignore_index = True) temp_df=temp_df.drop(temp_df[ temp_df['DATE'] == row[1] ].index) if month == 'June' and 'July' not in date and 'Lancaster - SAT ONLY' in row[0]: date_list = date.split("-") dic = {"LOCATION":row[0],"DATE":str(date_list[0]),"MONTH":row[2],"LANCASTER":'L',"SPITFIRE":'S','HURRICANE':'H','DAKOTA':'--'} temp_df=temp_df.append(dic, ignore_index = True) dic = {"LOCATION":row[0],"DATE":str(date_list[1]),"MONTH":row[2],"LANCASTER":'--',"SPITFIRE":'S','HURRICANE':'H','DAKOTA':'--'} temp_df=temp_df.append(dic, ignore_index = True) temp_df=temp_df.drop(temp_df[ temp_df['DATE'] == row[1] ].index) if month == 'June' and 'July' in date: date=date.replace(" July","") date_list = date.split("-") for j in range(int(date_list[0]),31): dic = {"LOCATION":row[0],"DATE":str(j),"MONTH":row[2],"LANCASTER":row[3],"SPITFIRE":row[4],'HURRICANE':row[5],'DAKOTA':row[6]} temp_df=temp_df.append(dic, ignore_index = True) for j in range(1,int(date_list[1])+1): dic = {"LOCATION":row[0],"DATE":str(j),"MONTH":'July',"LANCASTER":row[3],"SPITFIRE":row[4],'HURRICANE':row[5],'DAKOTA':row[6]} temp_df=temp_df.append(dic, ignore_index = True) temp_df=temp_df.drop(temp_df[ temp_df['DATE'] == row[1] ].index) if month == 'July' and 'August' not in date: date_list = date.split("-") for j in range(int(date_list[0]),int(date_list[1])+1): dic = {"LOCATION":row[0],"DATE":str(j),"MONTH":row[2],"LANCASTER":row[3],"SPITFIRE":row[4],'HURRICANE':row[5],'DAKOTA':row[6]} temp_df=temp_df.append(dic, ignore_index = True) temp_df=temp_df.drop(temp_df[ temp_df['DATE'] == row[1] ].index) if month == 'July' and 'August' in date: date=date.replace(" August","") date_list = date.split("-") for j in range(int(date_list[0]),32): dic = {"LOCATION":row[0],"DATE":str(j),"MONTH":row[2],"LANCASTER":row[3],"SPITFIRE":row[4],'HURRICANE':row[5],'DAKOTA':row[6]} temp_df=temp_df.append(dic, ignore_index = True) for j in range(1,int(date_list[1])+1): dic = {"LOCATION":row[0],"DATE":str(j),"MONTH":'August',"LANCASTER":row[3],"SPITFIRE":row[4],'HURRICANE':row[5],'DAKOTA':row[6]} temp_df=temp_df.append(dic, ignore_index = True) temp_df=temp_df.drop(temp_df[ temp_df['DATE'] == row[1] ].index) if month == 'August' and 'September' not in date: date_list = date.split("-") for j in range(int(date_list[0]),int(date_list[1])+1): dic = {"LOCATION":row[0],"DATE":str(j),"MONTH":row[2],"LANCASTER":row[3],"SPITFIRE":row[4],'HURRICANE':row[5],'DAKOTA':row[6]} temp_df=temp_df.append(dic, ignore_index = True) temp_df=temp_df.drop(temp_df[ temp_df['DATE'] == row[1] ].index) if month == 'August' and 'September' in date: date=date.replace(" September","") date_list = date.split("-") for j in range(int(date_list[0]),32): dic = {"LOCATION":row[0],"DATE":str(j),"MONTH":row[2],"LANCASTER":row[3],"SPITFIRE":row[4],'HURRICANE':row[5],'DAKOTA':row[6]} temp_df=temp_df.append(dic, ignore_index = True) for j in range(1,int(date_list[1])+1): dic = {"LOCATION":row[0],"DATE":str(j),"MONTH":'September',"LANCASTER":row[3],"SPITFIRE":row[4],'HURRICANE':row[5],'DAKOTA':row[6]} temp_df=temp_df.append(dic, ignore_index = True) temp_df=temp_df.drop(temp_df[ temp_df['DATE'] == row[1] ].index) if month == 'September' and 'October' not in date: date_list = date.split("-") for j in range(int(date_list[0]),int(date_list[1])+1): dic = {"LOCATION":row[0],"DATE":str(j),"MONTH":row[2],"LANCASTER":row[3],"SPITFIRE":row[4],'HURRICANE':row[5],'DAKOTA':row[6]} temp_df=temp_df.append(dic, ignore_index = True) temp_df=temp_df.drop(temp_df[ temp_df['DATE'] == row[1] ].index) if month == 'September' and 'October' in date: date=date.replace(" October","") date_list = date.split("-") for j in range(int(date_list[0]),31): dic = {"LOCATION":row[0],"DATE":str(j),"MONTH":row[2],"LANCASTER":row[3],"SPITFIRE":row[4],'HURRICANE':row[5],'DAKOTA':row[6]} temp_df=temp_df.append(dic, ignore_index = True) for j in range(1,int(date_list[1])+1): dic = {"LOCATION":row[0],"DATE":str(j),"MONTH":'October',"LANCASTER":row[3],"SPITFIRE":row[4],'HURRICANE':row[5],'DAKOTA':row[6]} temp_df=temp_df.append(dic, ignore_index = True) temp_df=temp_df.drop(temp_df[ temp_df['DATE'] == row[1] ].index) temp_df.reset_index(drop=True, inplace=True) for i,row in temp_df.iterrows(): date = row[1] date=date.replace(' (30 Reserve)',"") temp_df.iat[i,1]=date for i,row in temp_df.iterrows(): month = row[2] day = row[1] if month == 'May': date = '2018-'+str(5)+"-"+str(day) elif month == 'June': date = '2018-'+str(6)+"-"+str(day) elif month == 'July': date = '2018-'+str(7)+"-"+str(day) elif month == 'August': date = '2018-'+str(8)+"-"+str(day) elif month == 'September': date = '2018-'+str(9)+"-"+str(day) temp_df.iat[i,1] = date temp_df = temp_df.drop('MONTH',axis=1) for i,row in temp_df.iterrows(): loc = row[0] if 'All available BBMF Aircraft' in loc: temp_df.iat[i,2] = 'L' temp_df.iat[i,3] = 'SSSSS' temp_df.iat[i,4] = 'HH' temp_df.iat[i,5] = 'D'Interestingly, with the following two lines of Code :-
if '13' in date and '15' in date and 'Royal' in text and 'Jul' in month: temp_df.iat[i,3]='L' temp_df.iat[i,4]='SS' temp_df.iat[i,5]='--' temp_df.iat[i,6]='D' elif '14' in date and 'Royal' in text and 'Jul' in month: temp_df.iat[i,3]='L' temp_df.iat[i,4]='SSS' temp_df.iat[i,5]='HH' temp_df.iat[i,6]='D'For the 14th July Date, the same Aircraft are assigned, as for the 13th and 15th Date 'Royal' Rows,
in the DataFrame output ?
Regards
Eddie Winch