{ "cells": [ { "cell_type": "code", "execution_count": 30, "metadata": {}, "outputs": [], "source": [ "from pathlib import Path\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 39, "metadata": {}, "outputs": [], "source": [ "paths = list(Path('../data/text').iterdir())\n", "labels = []\n", "texts = []\n", "\n", "for path in paths: \n", " for filepath in path.glob('*.txt'):\n", " if not filepath.name == 'LICENSE.txt':\n", " with open(filepath) as f:\n", " next(f)\n", " next(f)\n", " text = f.read().replace('\\u3000','').replace('\\n','')\n", " \n", " texts.append(text)\n", " labels.append(path.name)" ] }, { "cell_type": "code", "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "news_df = pd.DataFrame({\n", " 'label': labels,\n", " 'text': texts\n", "})" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [], "source": [ "news_df.to_csv('../data/news.csv.gz', compression='gzip', index=False)" ] } ], "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.7.3" } }, "nbformat": 4, "nbformat_minor": 2 }