{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import matplotlib.pyplot as plt\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# You need to use the parser before to get the csv file.\n", "my_data = pd.read_csv('bretzel.csv', index_col='date', dtype=str)\n", "my_data = my_data.replace(to_replace=[np.NaN], value='')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "btz_core_id = {\n", " 'Nathan': 'user502298447',\n", " 'Louison': 'user435924815',\n", " 'Clément': 'user451690413',\n", " 'Théo': 'user490556008',\n", " 'Léopold': 'user483543500',\n", " 'Arnaud': 'user469821944',\n", " }" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def words_frequency(data):\n", " words_freq = data['msg_text']\n", " words_freq = words_freq.astype(str)\n", " remove_list = [',', '.', '(', ')', '{', '}', '[', ']', '-']\n", " for char in remove_list:\n", " words_freq = words_freq.str.replace(char, '')\n", "\n", " # Replace apostrophes with spaces for word counting purposes\n", " words_freq = words_freq.astype(str).str.replace('\\'', ' ')\n", " words_freq = words_freq.str.lower().str.split(expand=True).stack().value_counts()\n", " return words_freq" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def plot_message_count(data):\n", " for name in btz_core_id:\n", " idx = data['sender_id']==btz_core_id.get(name)\n", " time_range = pd.to_datetime(data.index[idx], yearfirst=True).to_series().dt.date\n", " cumulative_count = 1+np.arange(time_range.shape[0])\n", " plt.plot(time_range, cumulative_count, label=name)\n", " plt.legend()\n", " plt.xlabel('Date')\n", " plt.ylabel('Nombre de messages')\n", " plt.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wf = words_frequency(my_data)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot_message_count(my_data)" ] } ], "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.11.3" }, "orig_nbformat": 4, "vscode": { "interpreter": { "hash": "e7370f93d1d0cde622a1f8e1c04877d8463912d04d973331ad4851f04de6915a" } } }, "nbformat": 4, "nbformat_minor": 2 }