Titanic Story
  • AI Chat
  • Code
  • Report
  • Beta
    Spinner

    What if we want to write a story with data a bout the Titanic that snak when it hit an ice wall.

    Althought titanic's story is sat but it's data makes us live with those pepole on that ship

    We want to dive into this data and extract pearls from its depths

    It is true that Titanic data is commonly used data, but in this stroy it will be difference

    # Import your packages 
    import pandas as pd
    import seaborn as sns
    import matplotlib.pyplot as plt
    %matplotlib inline
    # Read your data from csv file
    titanic = pd.read_csv('titanic_story.csv')
    titanic.head()

    To take the summary of your data can use `info() method it give types and non null columns and memory usage

    # Take summary data
    titanic.info()

    Use describe() method to take statistics such as mean , min, max and percentage soon.

    # take statistics 
    titanic.describe()
    # Extract the part name befor the comma
    titanic["surname"]=titanic["name"].str.split(",").str.get(0)
    titanic["surname"]

    We want to count numbers of passengers are survive

    Use value_count() method

    we see here zero indicates to death people and one indicate to survive

    # Count numbers of survived passengers
    passengers_survived = titanic['survived'].value_counts()
    passengers_survived
    # The numbers of passengers  they didn't live
    passengers_is_dead = titanic.loc[titanic['survived']==0]
    passengers_is_dead
    # To sure the numbers is dead
    passengers_is_dead.survived.value_counts()
    passengers_survived = titanic.loc[titanic['survived']==1]
    passengers_survived
    # Define function to count all passengers
    def count_all_passengers(x, y):
        """Return numbers of titanic passengers"""
        all_passengers = x +y
        return all_passengers
    count_all_passengers(500, 809)