{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "本章のコードは、JupyteNotebookではなく、GoogleColaboratoryで入力するコードですが、コピペできるように公開しておきます。" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A.3.1 データの読み込み" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "# ファイル一覧の表示\n", "!ls\n", "\n", "# pandasで読み込み\n", "import pandas as pd\n", "df_test = pd.read_csv('test.csv')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### A.3.1.2" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "!pip install -U -q PyDrive\n", "\n", "from pydrive.auth import GoogleAuth\n", "from pydrive.drive import GoogleDrive\n", "from google.colab import auth\n", "from oauth2client.client import GoogleCredentials\n", "\n", "auth.authenticate_user()\n", "gauth = GoogleAuth()\n", "gauth.credentials = GoogleCredentials.get_application_default()\n", "drive = GoogleDrive(gauth)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "id = 'hoge' # 1.でコピーしたid= より後の部分\n", "downloaded = drive.CreateFile({'id': id})\n", "downloaded.GetContentFile('test.csv') # test.csvを適当な文字列に変更\n", "\n", "# pandasで読み込み\n", "import pandas as pd\n", "# test.csvを先ほど書き換えた適当な文字列に変更\n", "df_test = pd.read_csv('test.csv') " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A.3.2 データのダウンロード" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#データフレームをcsv形式で書き出す\n", "df_submission.to_csv(‘submission.csv', index=False)\n", "\n", "#GoogleColaboratory特有のライブラリを使い、ダウンロードする\n", "from google.colab import files\n", "files.download('submission.csv')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A.4 matplotlibで日本語を使う方法" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "!apt-get -y install fonts-ipafont-gothic\n", "import matplotlib.pyplot as plt\n", "plt.rcParams['font.family'] = 'IPAPGothic'\n", "\n", "# 以下具体例\n", "plt.plot([1,2])\n", "plt.title('日本語が使えるよ')" ] } ], "metadata": { "anaconda-cloud": {}, "kernelspec": { "display_name": "Python [conda root]", "language": "python", "name": "conda-root-py" }, "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.5.2" }, "toc": { "colors": { "hover_highlight": "#DAA520", "running_highlight": "#FF0000", "selected_highlight": "#FFD700" }, "moveMenuLeft": true, "nav_menu": { "height": "84px", "width": "252px" }, "navigate_menu": true, "number_sections": false, "sideBar": true, "threshold": 4, "toc_cell": false, "toc_section_display": "block", "toc_window_display": true, "widenNotebook": false } }, "nbformat": 4, "nbformat_minor": 1 }