{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "associatedRecipe": "compute_flight_data_prepared_with_python",
    "creator": "tara",
    "createdOn": 1618423713335,
    "tags": [
      "recipe-editor"
    ],
    "customFields": {}
  },
  "cells": [
    {
      "cell_type": "code",
      "metadata": {},
      "outputs": [],
      "execution_count": 0,
      "source": [
        "# -*- coding: utf-8 -*-\n",
        "import dataiku\n",
        "import pandas as pd, numpy as np\n",
        "from dataiku import pandasutils as pdu\n",
        "\n",
        "# This code is an example of how\n",
        "# DSS can work with different tools\n",
        "\n",
        "# Read recipe inputs\n",
        "flight_data_input \u003d dataiku.Dataset(\"flight_data_input\")\n",
        "df \u003d flight_data_input.get_dataframe()\n",
        "\n",
        "# Plot a sample of the data\n",
        "df.head()\n",
        "\n",
        "df.dtypes\n",
        "\n",
        "df.describe()\n",
        "\n",
        "total \u003d df.shape[0]\n",
        "for cols in df.columns:\n",
        "    count \u003d df[df[cols].isna()\u003d\u003dTrue].shape[0]\n",
        "    ratio \u003d ( count / total )*100\n",
        "    print(f\u0027There are {count} NAs [{ratio:.2f}%] in the column: {cols} \u0027)\n",
        "\n",
        "print(df.shape)\n",
        "df_clean \u003d df.dropna(subset\u003d[\"ArrDelay\"])\n",
        "print(df_clean.shape)\n",
        "\n",
        "total \u003d df_clean.shape[0]\n",
        "for cols in df_clean.columns:\n",
        "    count \u003d df_clean[df_clean[cols].isna()\u003d\u003dTrue].shape[0]\n",
        "    ratio \u003d ( count / total )*100\n",
        "    print(f\u0027There are {count} NAs [{ratio:.2f}%] in the column: {cols} \u0027)\n",
        "\n",
        "df_clean.AirTime.describe()\n",
        "\n",
        "# You could continue cleansing the data using this code\n",
        "# as much as you want.\n",
        "\n",
        "# Write recipe outputs\n",
        "dataset \u003d dataiku.Dataset(\"flight_data_prepared_with_python\")\n",
        "dataset.write_with_schema(df_clean[[\"AirTime\"]])"
      ]
    }
  ]
}