<jupyter_start><jupyter_text>---<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
data = pd.read_csv("/content/train_and_test2.csv")
data.head()
data.describe()
data.describe().T<jupyter_output><empty_output><jupyter_text>Checking for null values<jupyter_code>data.isnull().sum().any()
data.isnull().sum()
data.Embarked.value_counts()
data.Embarked.mode()
data.Embarked = data.Embarked.fillna(0)
data.isnull().sum()
data.Age.hist(bins=50, legend=1)

plt.show()<jupyter_output><empty_output><jupyter_text>Checking for imbalanced data<jupyter_code>data.columns
data.rename({"2urvived":"Survived"},axis=1, inplace=True)
data.head()
# sur = list()
# not_sur = list()
sur = data[data['Survived'] == 1].shape[0]

sur
# sur = [i for i in range(1,sur+1)]
# print(sur)
not_sur = data[data['Survived'] == 0].shape[0]

not_sur
# not_sur = [i for i in range(1,not_sur+1)]

# print(not_sur)
# sur = np.asarray(sur)
# not_sur = np.asarray(not_sur)
LABELS = ['Not Survived','Survived']
count_classes = pd.value_counts(data['Survived'], sort = True)

count_classes
count_classes.plot(kind = 'bar', rot=15, color=['red','b'],)
plt.title("Data Distribution",size=15)
plt.xticks(range(2), labels = LABELS)
plt.ylabel("Frequency")
plt.show()<jupyter_output><empty_output><jupyter_text>**Above graph show total survived and not survived**  Pie chart<jupyter_code>plt.pie(count_classes, labels=LABELS, shadow=True, autopct = '%0.1f%%', explode=[0,0.1], startangle=90)
plt.title("Percentage of Survival and Non Survivals\n",size=15)
plt.axis('Equal')
plt.show()<jupyter_output><empty_output><jupyter_text>---  Gender wise data distribution<jupyter_code>data.head()
gen_counts = pd.value_counts(data['Sex'],)
gen_counts
gen_counts.plot(kind='bar', rot=1, color=['b','r'])
plt.xticks(range(2), labels=['Female','Male'])
plt.ylabel("Frequency")
plt.title("Gender wise data distribution", size=15)
plt.show()
plt.pie(gen_counts, labels=['Female','Male'], explode=[0,0.1], startangle=90, autopct="%0.2f%%")
plt.title("Gender Wise Data Distribution\n", size=15)
plt.show()<jupyter_output><empty_output><jupyter_text>Now to check who survived most Male or Female<jupyter_code>survived_data = data[data['Survived'] == 1]
survived_data.shape
gen_survived = pd.value_counts(survived_data.Sex, sort=True)
gen_survived
gen_survived.plot(kind='bar', rot=0, color=['r','b'])
plt.title("Survived genders", size=15)
plt.xticks(range(2), labels=['Male', "Female"])
plt.show()
plt.pie(gen_survived, labels=['Male','Female'],autopct="%0.2f%%", startangle=180, explode=[0,0.1])
plt.title("Survived Genders\n", size=15)
plt.show()<jupyter_output><empty_output><jupyter_text>Now to check who died most Male or Female<jupyter_code>not_Servived_Data = data[data['Survived'] == 0]
not_Servived_Data.shape
not_Servived_Data = pd.value_counts(not_Servived_Data['Sex'])
not_Servived_Data
not_Servived_Data.plot(kind='bar',rot=0, color=['c','r'])
plt.title("Gender who died most", size=15)
plt.xticks(range(2), labels=['Female','Male'])
plt.ylabel("Frequency")
plt.show()
plt.pie(not_Servived_Data, labels=['Male',"Female"], autopct="%0.1f%%", explode=[0,.1])
plt.title("Percenatge of Gender who died most\n", size=15)

plt.show()<jupyter_output><empty_output><jupyter_text>Analyzing Passenger's Class<jupyter_code>data.columns
data.rename({"Pclass":"Passenger_Class"}, axis=1, inplace=1)
data.columns
data.Passenger_Class.unique() 
data[data.Passenger_Class == 1].shape
data[data.Passenger_Class == 2].shape
data[data.Passenger_Class == 3].shape
data.shape[0] == data[data.Passenger_Class == 1].shape[0] + data[data.Passenger_Class == 2].shape[0] + data[data.Passenger_Class == 3].shape[0]
# --------------------------------------------------------------------------------------
p_class = data.Passenger_Class.value_counts()
p_class
p_class.plot(kind='bar',rot=15, color = ['r','g','b'])
plt.xticks(range(3), labels=['Lower Class(3)','VIP Class(1)','Middle Class(2)'])
plt.title("Passenger Classes\n", size=15)
plt.show()
plt.pie(p_class,explode=[0,0.1,.1],
        labels=['Lower Class(3)','VIP Class(1)','Middle Class(2)'],shadow=True,
        autopct='%0.1f%%', startangle=90,radius=1)
plt.title("Passenger Classes Percentage Wise\n", size=15)
plt.show()<jupyter_output><empty_output><jupyter_text>--- Now to find how many **VIP, MIDDLE, LOWER** class people who survived<jupyter_code>data.head(2)
vip_sur = data[(data.Passenger_Class == 1) & (data.Survived == 1)]
vip_sur.tail()
vip_sur.shape
vip_sur.Passenger_Class.unique()
vip_sur = vip_sur.Sex.value_counts()
vip_sur
vip_sur.plot(kind='bar', color=['g','r'], rot=1)
plt.xticks(range(2), labels=['Male','Female'])
plt.title("Ratio of VIP Male and Female who Survived\n", size=15)
plt.show()

plt.pie(vip_sur, labels=['Male','Female'], autopct="%.1f%%",explode=[0,0.1],shadow=True)

plt.title("Percentage of VIP Male and Female who Survived\n", size=15)
plt.show()
# -------------------------------------------------------------------
middle_sur = data[(data['Passenger_Class'] == 2) & (data.Survived == 1)]
middle_sur.tail()
middle_sur.shape
middle_sur = middle_sur.Sex.value_counts()
middle_sur
middle_sur.plot(kind='bar',rot=1, color=['g','m'])
plt.xticks(range(2), labels=['Male','Female'])
plt.title("Ratio of Middle Class Male and Female who Survived\n", size=15)
plt.show()
plt.pie(middle_sur, labels=['Male','Female'], explode=[0,0.1], shadow=True, autopct='%.1f%%')
plt.title("Percentage of Middle Class Male and Female who Survived\n", size=15)
plt.show()
# ---------------------------------------------------------------------------
lower_sur = data[(data.Passenger_Class == 3) & (data.Survived == 1)]
lower_sur.tail() 
lower_sur.shape
lower_sur = pd.value_counts(lower_sur.Sex)
lower_sur
lower_sur.plot(kind='bar', rot=1, color=['c','m'])
plt.xticks(range(2), labels=['Male','Female'])
plt.title("Ratio of Lower Class Male and Female who Survived\n", size=15)
plt.show()

plt.pie(lower_sur, labels=['Male','Female'], explode=[0,0.1], autopct='%0.1f%%', shadow=True, startangle=90)
plt.title("Percentage of Lower Class Male and Female who Survived\n", size=15)
plt.show()<jupyter_output><empty_output><jupyter_text>Now finding many childs are in Titanic and how much of them survived and not survived<jupyter_code>data.head()
 data.Age.unique()
child_sub_data = data[data.Age < 12.0]

child_sub_data.head()
child_sub_data.shape
c_sub_data = child_sub_data.Sex.value_counts()
c_sub_data
c_sub_data.plot(kind='bar', rot=1, color=['m','c'])
plt.title('Data of Child Under 10\n', size=15)
plt.xticks(range(2), labels=['Girl','Boy'])
plt.ylabel("Counts")
plt.show()
# ----------------------------------------------------
plt.pie(c_sub_data, explode=[0,.1],
        labels=["Girl","Boy"],
        autopct="%.2f%%",
        shadow=True,
        startangle=120)

plt.title("Percenatge of Child under 10\n", size=15)
plt.show()
# -------------------------------------------------------------<jupyter_output><empty_output><jupyter_text>Survival from above data<jupyter_code>sur_child = child_sub_data[child_sub_data.Survived == 1]

sur_child.head()
sur_child.shape
sur_child = sur_child.Sex.value_counts()
sur_child
sur_child.plot(kind='bar', rot=1, color=['r','g'])
plt.xticks(range(2), labels=['Girl','Boys'])
plt.title("Ratio of Survival Under 10\n", size=15)
plt.ylabel("Counts")
plt.show()
plt.pie(sur_child, explode=[0,0.1],
        labels=['Girls','Boys'],
        autopct='%.1f%%',
        shadow=1,
        startangle=120,
        wedgeprops = {'linewidth': 5})

plt.title('Percentage of Survivals under 10', size=15)
plt.show()<jupyter_output><empty_output><jupyter_text>Correlation<jupyter_code>numerical_data = data.iloc[::,[1,3,-1]]
numerical_data.corr().plot(kind='bar', rot=0)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.22565290106779878, 'fraction_numerical': 0.023800334491187444, 'mean_word_length': 5.330618892508143, 'pattern_counts': {'":': 2, '<': 50, '<?xml version=': 0, '>': 49, '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': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '398483', 'license': 'MIT', 'n_tokens_mistral': 3113, 'n_tokens_neox': 2882, 'n_words': 484, 'path': '.ipynb_checkpoints/Titanic_EDA-checkpoint.ipynb', 'repo_name': 'Shahrayar123/Titanic_Exploratory_Data_Analysis', 'size': '7773'}