<jupyter_start><jupyter_text>In each cell complete the task using pandas<jupyter_code>import pandas as pd
import numpy as np<jupyter_output><empty_output><jupyter_text>Read in the titanic.csv file in the `~/data` directory as a pandas dataframe called **df**<jupyter_code>df=pd.read_csv('https://raw.githubusercontent.com/gumdropsteve/intro_to_python/main/day_09/data/titanic.csv')
df<jupyter_output><empty_output><jupyter_text>Display the head of the dataframe<jupyter_code>df.head()<jupyter_output><empty_output><jupyter_text>What is the percentage of people who survived? (hint find the mean of the survival column)<jupyter_code>df['Survived'].mean()<jupyter_output><empty_output><jupyter_text>How many women and how many men survived?<jupyter_code>df['Sex'].value_counts()<jupyter_output><empty_output><jupyter_text>What is the percentage of people that survied who paid a fare less than 10?<jupyter_code>df1=(df['Fare']<10).mean()
df1<jupyter_output><empty_output><jupyter_text>What is the average age of those who didn't survive?<jupyter_code>df2= df[df['Survived'] == 0] ['Age'].mean()
df2<jupyter_output><empty_output><jupyter_text>What is the average age of those who did survive?<jupyter_code>df2= df[df['Survived'] == 1] ['Age'].mean()
df2<jupyter_output><empty_output><jupyter_text>What is the average age of those who did and didn't survive grouped by gender?<jupyter_code>df3 = df.groupby(by='Sex')
df3['Age'].mean()<jupyter_output><empty_output><jupyter_text>Tidy GDP Manipulate the GDP.csv file and make it tidy, the result should be a pandas dataframe with the following columns:* Country Name* Country Code* Year* GDP<jupyter_code>df=pd.read_csv('https://raw.githubusercontent.com/gumdropsteve/intro_to_python/main/day_09/data/gdp.csv ')
df
#show the colmn of the csv file
df.columns
#Show the years column
df.columns[4:62]
# Explore Years colomn

years  = [df.iloc[0  , 4:62] for i in range(1960,2017,1)]
   
years
#remove unnessesery column
GDP_df = df.drop(columns=['Indicator Name', 'Indicator Code', 'Unnamed: 62'])
GDP_df
# use melt function to create Year colomn
GDP_df = GDP_df.melt(id_vars=['Country Name', 'Country Code'], var_name='Year', value_name='GDP')
GDP_df

GDP_df['Year'].unique()
#count null value
GDP_df.isna().sum()
GDP_df.dropna()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12634756360500216, 'fraction_numerical': 0.015523932729624839, 'mean_word_length': 7.375451263537906, 'pattern_counts': {'":': 0, '<': 42, '<?xml version=': 0, '>': 41, 'https://': 2, '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': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '189046', 'license': 'Apache-2.0', 'n_tokens_mistral': 895, 'n_tokens_neox': 855, 'n_words': 197, 'path': 'panda.ipynb', 'repo_name': 'helah20/Python', 'size': '2319'}