{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Univariate Datetime Summary\n\nExample of univariate eda summary for a datetime variable. Here we look at posting times for TidyTuesday tweets.\n\nThe datetime summary computes the following:\n\n- A time seriesplot aggregated according to the `ts_freq` parameter\n- Barplots showing counts by day of week, month, hour of day, day of month\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import warnings\nimport pandas as pd\nimport plotly\nimport intedact\n\nwarnings.filterwarnings(\"ignore\")\n\ndata = pd.read_csv(\n    \"https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/tidytuesday_tweets/data.csv\"\n)\ndata[\"created_at\"] = pd.to_datetime(data.created_at)\nfig = intedact.datetime_summary(data, \"created_at\", fig_width=700)\nplotly.io.show(fig)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "By default, the summary tries to infer reasonable units for the time differences and time series. We can change\nthese by using time unit strings for the `ts_freq` and `delta_units` parameters.\n\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig = intedact.datetime_summary(\n    data, \"created_at\", ts_freq=\"1 day\", fig_width=700\n)\nplotly.io.show(fig)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Example of changing plot type, removing trend line, and removing outliers.\n\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig = intedact.datetime_summary(\n    data,\n    \"created_at\",\n    ts_type=\"markers\",\n    trend_line=\"none\",\n    upper_quantile=0.99,\n    fig_width=700\n)\nplotly.io.show(fig)"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.9.12"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}