text: import sys
  import pandas as pd
  from sqlalchemy import create_engine
  
  
  def load_data(messages_filepath, categories_filepath):
      """
      This function loads two csv files as pandas dataframes and merge them into one.
      
      Parameters:
      messages_filepath (string type): location of the messages csv file
      categories_filepath (string type) : location of the categories csv file
      
      Returns: merged dataframe of messages and categories on each id 
      """
      messages = pd.read_csv(messages_filepath)
      categories = pd.read_csv(categories_filepath)
      df = messages.merge(categories, on='id')
      return df
  
  def clean_data(df):
      """
      This function cleans the input dataframe with reseting index
      and converting category values to numbers 0 or 1.
  
      Parameters: df (pandas dataframe)
      
      Returns: df (pandas dataframe)
      """
      
      categories = df['categories'].str.split(pat=';', expand=True)
      row = categories.iloc[0,:]
      category_colnames = row.apply(lambda x:x.split('-')[0]).values.tolist()
      categories.columns = category_colnames
      for column in categories:
          categories[column] = categories[column].str[-1:]
          categories[column] = categories[column].astype(int)
      df.drop('categories', axis=1, inplace=True)
      df = pd.concat([df, categories], axis=1)
      df.drop_duplicates(inplace=True)
      
      return df
      
  
  
  def save_data(df, database_filepath):
      """
      This function exports a dataframe file as a sql file.
  
      Parameters: 
      df (pandas dataframe)
      database_filepath (string): the location where database file should be saved 
      
      """
      
      engine = create_engine('sqlite:///' + database_filepath)
      df.to_sql('Message_new', engine, index=False) 
  
  
  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))
          #print('data file path:', database_filepath)
          #print('type:', type(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()
  