text: # import libraries
  import sys
  import pandas as pd
  import numpy as np
  import sqlite3
  from sqlalchemy import create_engine
  
  
  def load_data(messages_filepath, categories_filepath):
      
      """
      input: 
      messages_filepath - CSV file 
      categories_filepath - CSV file
      
      output:
      df - merged dataset
      
      """
      
      # load messages dataset
      messages = pd.read_csv(messages_filepath)
      
      # load categories dataset
      categories = pd.read_csv(categories_filepath)
      
      # merge datasets
      df = messages.merge(categories, on='id')
      
      return df
  
  def clean_data(df):
      
      """
      imput:
      df - merged dataset
      
      output:
      df - cleaned dataset
      
      """
      
      # create a dataframe of the 36 individual category columns
      categories = df['categories'].str.split(';', expand=True)
      
      # select the first row of the categories dataframe
      row = categories[categories.index==0]
      category_colnames = [(row[i][0])[0:-2] for i in range(36)]
      
      # rename the columns of `categories`
      categories.columns = category_colnames
      
      for column in categories:
      
      # set each value to be the last character of the string
          categories[column] = categories[column].str[-1]
      
      # convert column from string to numeric
          categories[column] = pd.to_numeric(categories[column].astype(str))
      
      #Change it to multilabel for later model fitting and cross validation
      for cl in categories.columns:
          categories[cl] = (categories[cl]==1)*1
          
      # drop the original categories column from `df`
      df.drop('categories', axis=1, inplace=True)
      
      # concatenate the original dataframe with the new `categories` dataframe
      df = pd.concat([df, categories], axis=1)
      
      return df
  
  
  def save_data(df, database_filepath):
      
      """
      input:
      df - clean data
      
      output:
      crate SQLITE database and load the cleaned data
      
      """
      #Loading clean data from database
      engine = create_engine('sqlite:///{}'.format(database_filepath))
      df.to_sql('df_clean', engine, index=False, if_exists='replace')
  
  def main():
      if len(sys.argv) == 4:
  
          messages_filepath, categories_filepath, database_filepath = sys.argv[1:]
  
          print('Loading data...\n    MESSAGES: {}\n    CATEGORIES: {}'
                .format(messages_filepath, categories_filepath))
          df = load_data(messages_filepath, categories_filepath)
  
          print('Cleaning data...')
          df = clean_data(df)
          
          print('Saving data...\n    DATABASE: {}'.format(database_filepath))
          save_data(df, database_filepath)
          
          print('Cleaned data saved to database!')
      
      else:
          print('Please provide the filepaths of the messages and categories '\
                'datasets as the first and second argument respectively, as '\
                'well as the filepath of the database to save the cleaned data '\
                'to as the third argument. \n\nExample: python process_data.py '\
                'disaster_messages.csv disaster_categories.csv '\
                'DisasterResponse.db')
  
  
  if __name__ == '__main__':
      main()