概要 分析のためにデータ集めしていると、たまに マジか!? と思うサイズの CSV に出くわすことがある。なぜこんなに育つまで放っておいたのか、、、? このエントリでは普通には開けないサイズの CSV を pandas を使ってうまいこと処理する方法をまとめたい。 サンプルデータ たまには実データ使おう、ということで WorldBankから GDPデータを落とす。以下のページ右上の "DOWNLOAD DATA" ボタンで CSV を選択し、ローカルに zip を保存する。解凍した "ny.gdp.mktp.cd_Indicator_en_csv_v2.csv" ファイルをサンプルとして使う。 http://data.worldbank.org/indicator/NY.GDP.MKTP.CD?page=1 補足 pandas の Remote Data Access で WorldBan
今年読んだデータサイエンスおよびPython本の中でも最良の一冊でした. ホントに待ち望んでいた一冊でした. 実は密かに楽しみにしてた(待ち望んでいた)*1, 「Pythonによる医療データ分析入門」, 一通り読ませていただきましたので, Pythonによる医療データ分析入門の感想 分析100本ノック後にやると良いこと 探索的データサイエンスはデータサイエンスに関わる人すべてに関係する準備運動であり入り口であること 的な話を綴りたいと思います. なお, 最初に断っておくと, 新型コロナウイルス含む, 感染症とか流行病の話は一切触れておりません! このエントリーは純粋に「Pythonを使ったデータサイエンス」を志向した方向けのエントリーとなります. 新型コロナウイルスだの感染症関連だのを期待されている・そう思った方はぜひ他のページなどを見ていただけると幸いです. このエントリーのダイジェスト
PDFは扱いにくい PDFファイルをPythonで扱うのは大変です。 表がPDFの中に埋め込まれているケースも割とあります。 例えば 平成30年 全衛連ストレスチェックサービス実施結果報告書の中にはたくさんの表データが埋め込まれています。 例えばファイルの40ページの【表14 業種別高ストレス者の割合】を抜き出したいと思ったとします。 この表を選択して、Excelにコピペしてみましょう。 コピーして、Excelに貼り付けます。 おや?うまくいかないですね。 1つのセルの中に、全部のデータが羅列されてしまっています。 実はPythonを使ってこのPDF中の表を比較的簡単にcsvやExcelに変換することができます。 PythonでPDFの表をcsvに PythonでPDF内の表(テーブル)をcsvやexcelに変換する手順は2ステップです。 ステップ1. PDFから表をpandasのData
CodeZineを運営する翔泳社では、4月20日(月)に『現場で使える!pandasデータ前処理入門』を発売しました。本書では機械学習やデータサイエンスにおいて欠かせない「データ前処理」をPythonのライブラリ「pandas」で行う手法について解説。作業に必要な「きれいなデータ」をできるだけ効率よく用意してしまいましょう。 『現場で使える!pandasデータ前処理入門 機械学習・データサイエンスで役立つ前処理手法 』は、機械学習やデータサイエンスに欠かせない「きれいなデータ」を作る手法を解説した入門書です。 本書では機械学習で人気のPythonを用い、データ前処理においてもはや必須と言われるライブラリ「pandas」の使い方を説明します。データを活用するにしても、収集された生のデータは欠損値や外れ値などが混ざっておりそのままでは利用できません。このデータを前処理していかに利用しやすい形に
はじめに 機械学習や深層学習が人気の昨今ですが、それらのモデルの精度に最もクリティカルに影響するのはインプットするデータの質です。データの質は、データを適切に把握し、不要なデータを取り除いたり、必要なデータを精査する前処理を行うことで高めることができます。 本頁では、データ処理の基本ツールとしてPandasの使い方を紹介します。Pandasには便利な機能がたくさんありますが、特に分析業務で頻出のPandas関数・メソッドを重点的に取り上げました。 Pandasに便利なメソッドがたくさんあることは知っている、でもワイが知りたいのは分析に最低限必要なやつだけなんや…!、という人のためのPandasマニュアルです。 また、単に機能を説明するだけでは実際の処理動作がわかりにくいため、ここではSIGNATE(旧DeepAnalytics)のお弁当の需要予想を行うコンペのデータを拝借し、このデータに対
100 pandas tricks to save you time and energy Below you'll find 100 tricks that will save you time and energy every time you use pandas! These the best tricks I've learned from 5 years of teaching the pandas library. "Soooo many nifty little tips that will make my life so much easier!" - C.K. "Kevin, these tips are so practical. I can say without hesitation that you provide the best resources for
# https://www.kaggle.com/abcsds/pokemon から取得した Pokemon.csv を読み込む。 df = pd.read_csv("Pokemon.csv") # df とは、 pandas の DataFrame 形式のデータを入れる変数として命名 https://www.kaggle.com/abcsds/pokemon によると、各カラム(列)は次のような意味らしいです。 #: PokeDex index number Name: Name of the Pokemon Type 1: Type of pokemon Type 2: Other Type of Pokemon Total: Sum of Attack, Sp. Atk, Defense, Sp. Def, Speed and HP HP: Hit Points Attack: At
こういうことやぞ サムネイルで描いた事がこのエントリーの全てです. Pythonでは、「pandas」というライブラリを使ってデータ分析や解析をすることが非常に多いです. でも、「利用方法(またはユースケース)」に合わせた入門ってあんまりない気がします. ということで、「PyCon mini Sapporo 2019」でそんな話をしてきました. sapporo.pycon.jp 訳あって資料およびJupyter notebookは非公開*1ですが、こちらにその基本とかをまとめます. TL;DR - このエントリーは 実務や趣味のデータ分析でpandasを使う例を紹介します. 初歩的な使い方から中級者になるまでのヒントになると思います. なお,統計テクニック・機械学習には触れません・やりません. なお、対象読者は「そこそこPythonとJupyter notebookが使えてこれからデータ分
マイクロアドの京都研究所で機械学習エンジニアをしている田中です。 機械学習を利用したユーザーの行動予測の研究開発などを担当しています。 今回は、データの前処理に関するお話をしたいと思います。 データの縦横変換 縦横変換するためのpandasの関数 省メモリに縦横変換する サンプルデータの準備 pandas.Categoricalの活用 scipy.sparseの疎行列クラスの活用 さいごに 参考 データの縦横変換 機械学習や統計解析をする際に頻出するデータの前処理の1つに、データの縦横変換があります。 縦横変換とは、縦持ち(またはlong型)のデータと、横持ち(またはwide型)のデータを互いに変換することを指します。 縦持ちのデータの例 横持ちのデータの例 例示したこの2つのテーブルは、表現形式こそ異なりますが、表しているデータ自体はどちらも同じものになります。 ユーザーの行動予測をする
データの集計は、ExcelよりPython使ったほうが100倍早い(pandas-profiling, pixiedust)Pythonpandasデータ分析データ可視化pandas-profiling Pythonのpandas-profilingと、pixiedustの2つのライブラリを使うと、データの集計・グラフの作成が、感動的なほど早く終わることを実感したので共有します。 Excelでデータ集計・グラフ作成した場合と比較すると、体感で100倍くらい早く終わります(誇張ではなく) Pythonで爆速でデータ集計する方法(体感所要時間:5分) 前提: 以下の環境が整備されていることは、前提とします。 Pythonのインストール(約30分) データ分析に必要な各種ライブラリのインストール(約30分) →numpy, matplotlib, pandas, jupyter など →Anac
TL;DR アウトオブコア、かつマルチコアでデータ処理を行えるVaexの紹介です。 string関係のメソッドで平均して100倍以上の高速化が確認できました。(作者のベンチマークだと最大1000倍) 文字列処理以外でも数倍~数十倍の高速化が行えそうです。 この記事では性能の比較のみ行い、解説記事は別で書こうと思います。 pandasより1000倍早いフレームワーク? 今週、興味深い記事を読みました。重要な部分だけ抜き出すと次のような内容です。 Vaexの最近のアップデートでの文字列処理が超早くなった 32コアだとpandasと比べて1000倍早い towardsdatascience.com 1000倍って本当なの?って感じですよね。そもそも自分はVaex自体を知らなかったので調べてみました。 ちなみに調べていて気づいたのですが、この記事の著者はVaexの作者なんですよね。 疑っているわけ
Bokeh Plotting Backend for Pandas and GeoPandas. Contribute to PatrikHlobil/Pandas-Bokeh development by creating an account on GitHub. インストール pip install pandas-bokeh 使い方 最初にpandas_bokehの読み込みコマンドを実行します。今回はjupyter notebook上で使いたいので、ouutput_notebook としました。 import pandas_bokeh pandas_bokeh.output_notebook() plotをplot_bokehに変えるだけ Pandasをよく使っている人は、DataFrame.plot.bar()でチャートを書くことができることは知っていると思います。Pandas-B
時系列データ分析の可視化 僕が普段扱っているデータ(エネルギーデータ)の可視化をPythonを使って行うためのメモです。 Githubにまとめもあげています。 エネルギーデータの分析にPythonを使うときの参考になればと思っています。私も勉強中なのでこんなのがあればというものがあれば教えてください。m(_ _;)m ※あくまで、普段使っているエネルギーデータに対応したものなので、適宜変更していただければと思います。また、使用データはGithubに置いています。 概要 エネルギーデータを使用(1h間隔のデータ) 使用言語はPython 可視化は、pandasのplot, matplotlib, seabornなど githubではJupyterNotebookで実現 Pandas,Seabornの両方で行っているものもあります Bokehも使ってインタラクティブなチャートも使いたい 使用デ
今回は pandas で特定の値がいくつ数える方法について。 結論から先に書いてしまうと value_counts() という専用のメソッドがあるよ、という話。 使った環境は次の通り。 $ python -V Python 3.6.4 $ pip list --format=columns | grep -i pandas pandas 0.22.0 まずは pandas をインストールして Python の REPL を起動しておく。 $ pip install pandas $ python 続いて、サンプル用のデータフレームを作っておく。 何かのグレードが英字一文字で格納されたデータのようだ。 >>> import pandas as pd >>> data = [ ... "A", ... "B", ... "B", ... "C", ... ] >>> columns = ['g
最近、Pythonを使って機械学習を勉強しているがnumpyやpandas, グラフ作成辺りの体系的な知識が足りない気がしていたので、この辺りをまとめた本「Python for Data Analysis (第2版)」を読んだ。感想としてはもっと早くに読んでおくべきだったと思う。今まで何となく書いていたnumpyやpandasが割と頭の中で整理できたと思う。 日本語版は第1版の翻訳が出ているようだ。Amazonのレビューを見ると第1版はPython2系列で書かれており、今読むとしたら内容が古いのでオススメはしない。第2版ではPython3で書かれている。 以下に学んだことをピックアップしておく。 IPythonでは変数の後に「?」をつけると変数の情報が見れる リストに要素を逐次的に追加していく場合、extendメソッドを使った方が要素を結合するよりも速い arr2d[0][2]とarr2d
pandas-datareaderを使うと、Web上の様々なソースに簡単にアクセスして、株価や為替レート、人口などのデータをpandas.DataFrameとして取得できる。 pandas-datareader — pandas-datareader 0.8.0 documentation pydata/pandas-datareader ここでは以下の内容について説明する。 pandas-datareaderの概要 インストール データソース 株価(Alpha Vantage) データ取得 CSVで保存 グラフをプロット 人口、GDPなど(World Bank) データ取得 indicator 階層データの整形 以下のサンプルコードのpandas-datareaderのバージョンは0.8.1。2020年5月22日時点で動作を確認している。バージョンやデータソースの仕様が変わると動作しない
English version available on dev.to はじめに matplotlibで作ったグラフの細かい調整は大変です。何をどういじったらいいのかを調べるのにアホみたいに時間がかかることがあります1。「何を」の部分の名前さえわからないこともあります。解決の糸口を掴んだ後も希望通りの見た目を実現するまでの最後のアレンジに苦労することが多いです2。これらの問題はmatplotlibのグラフがどういう要素で構成されていて、それらに対してどういうことができるかを知ることでいくらか改善されます。私はひたすらStack Overflowの回答を読むことでいろんなつまづきを時間をかけて乗り越えてきましたが、最近になってようやく公式チュートリアルにこの苦労を回避できたはずのヒントが書いてあることに気づきました。初期にざっと目を通したのですが「なるほど、よくわからん」と判断して読み込まな
この記事はplotlyとpandasを結びつけるライブラリ"cufflinks"の紹介、およびそれを利用した金融関連のデータ描画、pandas_datareaderや自作モジュールによる金融データの取得、自作モジュールによる金融データの操作を行います。 cufflinks 使い方 公式: GitHub - santosjorge/cufflinks This library binds the power of plotly with the flexibility of pandas for easy plotting. このライブラリーは簡単なプロットのために「plotlyの力」と「pandasの柔軟性」を結びつけます。 2017年12月現在、condaではインストールできません。 anaconda cloudで探すと(またはぐぐると) biocondaでRNAがなんとかとか言っている
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く