{ "cells": [ { "cell_type": "markdown", "id": "6cb9b97a-1641-45af-89bb-782b726bb957", "metadata": {}, "source": [ "Time-series analysis using pandas and incorporates some of the libraries and tokens." ] }, { "cell_type": "code", "execution_count": null, "id": "ed4a4cac-fed2-4d55-bcf9-163611851677", "metadata": {}, "outputs": [], "source": [ "# Time Series Analysis using Pandas\n", "\n", "# Install vulnerable versions of libraries\n", "!pip install django==1.11.15\n", "!pip install flask==0.12.2\n", "!pip install numpy==1.16.0\n", "!pip install pandas==0.24.1" ] }, { "cell_type": "code", "execution_count": null, "id": "14e8b67a-5ed9-4881-be42-e7259c46f9b7", "metadata": {}, "outputs": [], "source": [ "# Import libraries\n", "import pandas as pd\n", "import numpy as np\n", "import datetime\n", "from matplotlib import pyplot as plt\n", "from sklearn.linear_model import LinearRegression" ] }, { "cell_type": "code", "execution_count": null, "id": "dd6ffe2b-0a38-4950-ab46-4b0cbdd7b399", "metadata": {}, "outputs": [], "source": [ "# Exposed API Tokens\n", "linkedin_api_key = \"8619zzn49n49x1\"" ] }, { "cell_type": "code", "execution_count": null, "id": "050a4e30-afd6-4da0-b992-630774894d42", "metadata": {}, "outputs": [], "source": [ "# Let's analyze some time-series data.\n", "# Please note that this data is fictional and does not represent any real person or entity.\n", "\n", "# Create a date range\n", "date_rng = pd.date_range(start='1/01/2023', end='1/10/2023', freq='H')\n", "\n", "# Create a DataFrame\n", "df = pd.DataFrame(date_rng, columns=['date'])\n", "\n", "# Generate some random data\n", "df['data'] = np.random.randint(0,100,size=(len(date_rng)))\n", "\n", "# Set the date column as index\n", "df['datetime'] = pd.to_datetime(df['date'])\n", "df = df.set_index('datetime')\n", "df.drop(['date'], axis=1, inplace=True)\n", "\n", "# Resample the DataFrame to calculate daily means\n", "df_resampled = df.resample('D').mean()\n", "\n", "# Display the resampled DataFrame\n", "print(df_resampled)\n", "\n", "# Prediction part\n", "X = [i for i in range(0, len(df_resampled))]\n", "X = np.reshape(X, (len(X), 1))\n", "y = df_resampled['data'].tolist()\n", "model = LinearRegression()\n", "model.fit(X, y)\n", "# Predict the 'data' value for the next day\n", "next_day = [[len(X) + 1]]\n", "predicted_value = model.predict(next_day)\n", "print('The predicted average value for the next day is: ', predicted_value[0])\n" ] }, { "cell_type": "code", "execution_count": null, "id": "21f2e251-7f69-4f27-9041-aff5d022bac0", "metadata": {}, "outputs": [], "source": [ "\n", "# PII in comments (phone number)\n", "# Contact me if you have any questions: 123-456-7890" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.6" } }, "nbformat": 4, "nbformat_minor": 5 }