<jupyter_start><jupyter_text>People Etiquettes on Air "It is impossible to overlook the extent to which civilization is built upon a renunciation of instinct,” <NAME> said.There is always a tension between how much we need to follow our instrincts and how much we need to yeild to the social conventions. The people of different age behave differently in Airplane travel. I have been over the plane quiet a few time so far. I have seen people go "Errrrr !! I see a baby on next seat." on plane travels. This made me to search for data to analyse how people behave on airplanes. The quick survey from fivethirthyeight.com will help us to find out the good-natured people on that we meet on flight travels.I have used pandas, numpy and mathplot for this data analysis.<jupyter_code>import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
url = 'https://raw.githubusercontent.com/rajasekarsr/data/master/flying-etiquette-survey/flying-etiquette.csv'
flying = pd.read_csv(url)
flying.head()
print('Flying-etiquette columns\n' + '-'*24)
print(flying.columns)
#To sample of data
print('Sample of Flying-etiquette\n' + '-'*20)
print(flying.sample(10))
#to findout how many values are missing
flying_missing = flying.isnull().sum()
flying_missing[flying_missing>0]
#precentage of missing values
total_cells = np.product(flying.shape)
total_cells = float(total_cells)
print (total_cells)
total_missing = flying_missing.sum()
percnt_missing = (total_missing/total_cells) * 100
print('The percentage of values missing in the dataset : ' + str(percnt_missing))
flying_missing[0:10]
dropped_na_values = flying.dropna(axis=0)
dropped_na_values.head()
#Total number of records after dropping
total_cells_of_dropped = np.product(dropped_na_values.shape)
total_cells_of_dropped = float(total_cells_of_dropped)
print ('Total number of rows after dropping records : ' + str (total_cells_of_dropped))
filled_flying = flying.fillna({
    'Gender': 'unknown',
    'Age' : 'unknown',
    'Household Income' : 'unknown',
    'Education' : 'unknown',
    'Location (Census Region)' : 'unknown'
    })
filled_flying.head()
dropped_na_values = filled_flying.dropna(axis=0)
dropped_na_values.head()
#Total number of records after dropping
total_cells_of_dropped = np.product(dropped_na_values.shape)
total_cells_of_dropped = float(total_cells_of_dropped)
print ('Total number of rows after dropping records : ' + str (total_cells_of_dropped))
filled_flying['Gender'].value_counts()
filled_flying['In general, is itrude to bring a baby on a plane?'].value_counts()<jupyter_output><empty_output><jupyter_text>Let us consider both these categorical variables,We are not interested to know if there is a relationship between the person gender and their tendency to accept a baby on a plane. In order to do so, we would have to use the Chi-Square test. But First, let's state our null and alternate hypothesis. Ho : There is no staistically significant relationship between these two variables.H1 : There is a staistically significant relationship between these two variables.In order to perfrom this test, we need to construct the contigency table for these two variables.<jupyter_code>contigency_table_flying = pd.crosstab(
filled_flying['Gender'],
filled_flying['In general, is itrude to bring a baby on a plane?'],
margins = True)
contigency_table_flying<jupyter_output><empty_output><jupyter_text>Now we can see the counts of the people who are very rude towards bringing baby on a flight. Each row in the above table will represents the count. The intersection of Male and No, not at all rude represent that there are 249 Male who think bring a baby on plane is not rude.<jupyter_code>#assign the gender counts to variables
male_count = contigency_table_flying.iloc[1][0:3].values
female_count = contigency_table_flying.iloc[0][0:3].values
unknown_count = contigency_table_flying.iloc[2][0:3].values

print (male_count, female_count, unknown_count)

#Plots the bar chart
fig = plt.figure(figsize=(10, 5))
sns.set(font_scale=1.8)
categories = ["No, not at all rude","Yes, Somewhat rude","Yes, very rude"]
p1 = plt.bar(categories, male_count, 0.55, color='#d62728')
p2 = plt.bar(categories, female_count, 0.55, bottom= male_count)
plt.legend((p2[0], p1[0]), ('Female', 'Male'))
plt.xlabel('Having Baby on plane')
plt.ylabel('Count')
plt.show()
f_obs = np.array ([contigency_table_flying.iloc[1][0:3].values,
                  contigency_table_flying.iloc[0][0:3].values])
f_obs
from scipy import stats
chisq = stats.chi2_contingency(f_obs)[0:3]
print 'Chi-square value = ', chisq[0],'\n P-value = ', '{:.6f}'.format (round (float (chisq[1]), 5))<jupyter_output>Chi-square value =  21.009407414417225 
 P-value =  0.000030
{'fraction_non_alphanumeric': 0.09663776696976105, 'fraction_numerical': 0.018397124127722563, 'mean_word_length': 5.709219858156028, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 14, 'https://': 1, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '231644', 'license': 'MIT', 'n_tokens_mistral': 1572, 'n_tokens_neox': 1488, 'n_words': 510, 'path': 'People_on_Air.ipynb', 'repo_name': 'rajasekarsr/People_on_Plane_DataAnalysis', 'size': '4736'}