<jupyter_start><jupyter_text>Flight Price Prediction(EDA and Feature Engineering)<jupyter_code># importing labraries
import pandas as pd
import numpy as np
import matplotlib as plt
import seaborn as sns
%matplotlib inline

train_df=pd.read_excel('/content/Data_Train.xlsx')
train_df.head()
test_df=pd.read_excel('/content/Test_set.xlsx')
test_df.head()
final_df=train_df.append(test_df)
final_df.head()
final_df.tail()
final_df.isnull().sum()
final_df.info()
#Feature Engineering Process
final_df['Date']=final_df['Date_of_Journey'].str.split('/').str[0]
final_df['Month']=final_df['Date_of_Journey'].str.split('/').str[1]
final_df['Year']=final_df['Date_of_Journey'].str.split('/').str[2]

final_df.head()
#also u can use this
final_df['Date']=final_df['Date_of_Journey'].apply(lambda x:x.split('/')[0])
final_df['Month']=final_df['Date_of_Journey'].apply(lambda x:x.split('/')[1])
final_df['Year']=final_df['Date_of_Journey'].apply(lambda x:x.split('/')[2])
#convert date month and year from object to integer
final_df['Date']=final_df['Date'].astype(int)
final_df['Month']=final_df['Month'].astype(int)
final_df['Year']=final_df['Year'].astype(int)

final_df.info()
#drop of Date_of_Journey because not in use
final_df.drop('Date_of_Journey',axis=1,inplace=True)
final_df.head(1)
#Arrival_Time
final_df['Arrival_Time']=final_df['Arrival_Time'].str.split(' ').str[0]
#or
final_df['Arrival_Time']=final_df['Arrival_Time'].apply(lambda x:x.split('/')[0])
final_df.head(1)
final_df['Arrival_hour']=final_df['Arrival_Time'].str.split(':').str[0]
final_df['Arrival_min']=final_df['Arrival_Time'].str.split(':').str[1]
final_df.head()
#convert arrival_hr and arrival_min from object to integer
final_df['Arrival_min']=final_df['Arrival_min'].astype(int)
final_df['Arrival_hour']=final_df['Arrival_hour'].astype(int)
final_df.info()
#drop the col Arrival_Time 
final_df.drop('Arrival_Time',axis=1,inplace=True)
final_df.head(1)
final_df['Dep_hour']=final_df['Dep_Time'].str.split(':').str[0]
final_df['Dep_min']=final_df['Dep_Time'].str.split(':').str[1]
final_df.head()
#convert Dep_hr and Dep_min from object to integer
final_df['Dep_min']=final_df['Dep_min'].astype(int)
final_df['Dep_hour']=final_df['Dep_hour'].astype(int)
final_df.info()
#drop col dep_time because it is not used
final_df.drop('Dep_Time',axis=1,inplace=True)
final_df.head(1)
final_df['Total_Stops'].unique()
final_df['Total_Stops']=final_df['Total_Stops'].map({'non-stop':0,'2 stops':2,'1 stop':1,'3 stops':3,'4 stops':4,'nan':2})
final_df.head(5)
final_df.drop('Route',axis=1,inplace=True)
final_df.head()
final_df['Additional_Info'].unique()
final_df['Duration_hour']=final_df['Duration'].str.split(' ').str[0].str.split('h').str[0]
final_df[final_df['Duration_hour']=='5m']
final_df['Duration_hour']=final_df['Duration_hour'].astype(int)
#drop duration_hour which is 5m
final_df.drop(6474,axis=0,inplace=True)
final_df.drop(2660,axis=0,inplace=True)
final_df['Duration_hour']=final_df['Duration_hour'].astype(int)
final_df.info()
#Drop Duration
final_df.drop('Duration',axis=1,inplace=True)
final_df.head(1)
final_df['Airline'].unique()
# Import label encoder
from sklearn import preprocessing
 
# label_encoder object knows how to understand word labels.
label_encoder = preprocessing.LabelEncoder()
 
# Encode labels in column 'species'.
final_df['Airline']= label_encoder.fit_transform(final_df['Airline'])
final_df['Source']= label_encoder.fit_transform(final_df['Source'])
final_df['Destination']= label_encoder.fit_transform(final_df['Destination'])
final_df['Additional_Info']= label_encoder.fit_transform(final_df['Additional_Info'])
 
#df['Airline'].unique()
final_df.shape
final_df.head()
pd.get_dummies(final_df,columns=['Airline','Source','Destination','Additional_Info'],drop_first=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1841136244082062, 'fraction_numerical': 0.012361914781693845, 'mean_word_length': 11.307443365695793, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '524302', 'license': 'MIT', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1453, 'n_words': 188, 'path': 'Flight_Price_Prediction(EDA_and_Feature_Engineering)_.ipynb', 'repo_name': 'GirishHiremath/ML', 'size': '3802'}