Created
          November 27, 2015 08:36 
        
      - 
      
 - 
        
Save peace098beat/76005a2eb8448dea008c to your computer and use it in GitHub Desktop.  
    [Pandas] 信号データの呼び出し
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | { | |
| "cells": [ | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "# Pandasで信号のロード" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 3, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "%matplotlib inline" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 4, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "import pandas as pd\n", | |
| "import numpy as np" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 39, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "import os\n", | |
| "import sys" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 40, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "pd.options.display.max_rows=5" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 41, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "# カレントパスの取得\n", | |
| "BASE_DIR = os.path.dirname(sys.argv[0])\n", | |
| "# パスの追加\n", | |
| "sys.path.append('E:\\Python\\GolfClassification/')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 42, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "from FiSig.AudioManager import AudioManager" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 82, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "['./wav/audio1.wav', './wav/audio2.wav', './wav/audio3.wav']" | |
| ] | |
| }, | |
| "execution_count": 82, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "audiofile_path_s = ['./wav/audio1.wav', './wav/audio2.wav', './wav/audio3.wav']\n", | |
| "audiofile_path_s" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 84, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "['audio1.wav', 'audio2.wav', 'audio3.wav']" | |
| ] | |
| }, | |
| "execution_count": 84, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "audiofile_basename_s = [os.path.basename(path) for path in audiofile_path_s]\n", | |
| "audiofile_basename_s" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 86, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "['audio1', 'audio2', 'audio3']" | |
| ] | |
| }, | |
| "execution_count": 86, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "audioname_s = [os.path.splitext(basename)[0] for basename in audiofile_basename_s]\n", | |
| "audioname_s" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 87, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "\n", | |
| "-------------------------\n", | |
| "ファイル名: audio1.wav\n", | |
| "チャンネル数: 2\n", | |
| "サンプル[Byte]: 2\n", | |
| "サンプリング周波数: 48000\n", | |
| "フレーム数: 24001\n", | |
| "パラメータ: (2, 2, 48000, 24001, 'NONE', 'not compressed')\n", | |
| "長さ(秒): 0.500020833333\n", | |
| "振幅幅 32767\n", | |
| "-------------------------\n", | |
| "\n", | |
| "\n", | |
| "-------------------------\n", | |
| "ファイル名: audio2.wav\n", | |
| "チャンネル数: 2\n", | |
| "サンプル[Byte]: 2\n", | |
| "サンプリング周波数: 48000\n", | |
| "フレーム数: 24001\n", | |
| "パラメータ: (2, 2, 48000, 24001, 'NONE', 'not compressed')\n", | |
| "長さ(秒): 0.500020833333\n", | |
| "振幅幅 32767\n", | |
| "-------------------------\n", | |
| "\n", | |
| "\n", | |
| "-------------------------\n", | |
| "ファイル名: audio3.wav\n", | |
| "チャンネル数: 2\n", | |
| "サンプル[Byte]: 2\n", | |
| "サンプリング周波数: 48000\n", | |
| "フレーム数: 24001\n", | |
| "パラメータ: (2, 2, 48000, 24001, 'NONE', 'not compressed')\n", | |
| "長さ(秒): 0.500020833333\n", | |
| "振幅幅 32767\n", | |
| "-------------------------\n", | |
| "\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "audio_manager_s = [AudioManager(f) for f in audiofile_path_s]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 88, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "[array([ -2.44148076e-04, -1.83111057e-04, -9.15555284e-05, ...,\n", | |
| " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00]),\n", | |
| " array([ -9.15555284e-05, -1.22074038e-04, -6.10370190e-05, ...,\n", | |
| " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00]),\n", | |
| " array([ 0.00012207, 0.00030519, 0.00030519, ..., 0. ,\n", | |
| " 0. , 0. ])]" | |
| ] | |
| }, | |
| "execution_count": 88, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "audio_data_s = [am.getData(mode='norm') for am in audio_manager_s]\n", | |
| "audio_data_s" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 89, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [ | |
| "fs = audio_manager_s[0].getFs()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 90, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "24001L" | |
| ] | |
| }, | |
| "execution_count": 90, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "N = audio_data_s[0].shape[0]\n", | |
| "N" | |
| ] | |
| }, | |
| { | |
| "cell_type": "markdown", | |
| "metadata": {}, | |
| "source": [ | |
| "## PandasのDataFrameを使ってみる" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 94, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "{'audio1': array([ -2.44148076e-04, -1.83111057e-04, -9.15555284e-05, ...,\n", | |
| " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00]),\n", | |
| " 'audio2': array([ -9.15555284e-05, -1.22074038e-04, -6.10370190e-05, ...,\n", | |
| " 0.00000000e+00, 0.00000000e+00, 0.00000000e+00]),\n", | |
| " 'audio3': array([ 0.00012207, 0.00030519, 0.00030519, ..., 0. ,\n", | |
| " 0. , 0. ])}" | |
| ] | |
| }, | |
| "execution_count": 94, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "table_dict = dict(zip(audioname_s, audio_data_s))\n", | |
| "table_dict" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 95, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "(24001L,)" | |
| ] | |
| }, | |
| "execution_count": 95, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "trange = np.linspace(0, N/float(fs), N)\n", | |
| "trange.shape" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 96, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<div>\n", | |
| "<table border=\"1\" class=\"dataframe\">\n", | |
| " <thead>\n", | |
| " <tr style=\"text-align: right;\">\n", | |
| " <th></th>\n", | |
| " <th>audio1</th>\n", | |
| " <th>audio2</th>\n", | |
| " <th>audio3</th>\n", | |
| " </tr>\n", | |
| " </thead>\n", | |
| " <tbody>\n", | |
| " <tr>\n", | |
| " <th>0.000000</th>\n", | |
| " <td>-0.000244</td>\n", | |
| " <td>-0.000092</td>\n", | |
| " <td>0.000122</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>0.000021</th>\n", | |
| " <td>-0.000183</td>\n", | |
| " <td>-0.000122</td>\n", | |
| " <td>0.000305</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>...</th>\n", | |
| " <td>...</td>\n", | |
| " <td>...</td>\n", | |
| " <td>...</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>0.500000</th>\n", | |
| " <td>0.000000</td>\n", | |
| " <td>0.000000</td>\n", | |
| " <td>0.000000</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>0.500021</th>\n", | |
| " <td>0.000000</td>\n", | |
| " <td>0.000000</td>\n", | |
| " <td>0.000000</td>\n", | |
| " </tr>\n", | |
| " </tbody>\n", | |
| "</table>\n", | |
| "<p>24001 rows × 3 columns</p>\n", | |
| "</div>" | |
| ], | |
| "text/plain": [ | |
| " audio1 audio2 audio3\n", | |
| "0.000000 -0.000244 -0.000092 0.000122\n", | |
| "0.000021 -0.000183 -0.000122 0.000305\n", | |
| "... ... ... ...\n", | |
| "0.500000 0.000000 0.000000 0.000000\n", | |
| "0.500021 0.000000 0.000000 0.000000\n", | |
| "\n", | |
| "[24001 rows x 3 columns]" | |
| ] | |
| }, | |
| "execution_count": 96, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "df = pd.DataFrame(table_dict, trange)\n", | |
| "df" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 98, | |
| "metadata": { | |
| "collapsed": false | |
| }, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/html": [ | |
| "<div>\n", | |
| "<table border=\"1\" class=\"dataframe\">\n", | |
| " <thead>\n", | |
| " <tr style=\"text-align: right;\">\n", | |
| " <th></th>\n", | |
| " <th>audio2</th>\n", | |
| " </tr>\n", | |
| " </thead>\n", | |
| " <tbody>\n", | |
| " <tr>\n", | |
| " <th>0.000000</th>\n", | |
| " <td>-0.000092</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>0.000021</th>\n", | |
| " <td>-0.000122</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>...</th>\n", | |
| " <td>...</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>0.500000</th>\n", | |
| " <td>0.000000</td>\n", | |
| " </tr>\n", | |
| " <tr>\n", | |
| " <th>0.500021</th>\n", | |
| " <td>0.000000</td>\n", | |
| " </tr>\n", | |
| " </tbody>\n", | |
| "</table>\n", | |
| "<p>24001 rows × 1 columns</p>\n", | |
| "</div>" | |
| ], | |
| "text/plain": [ | |
| " audio2\n", | |
| "0.000000 -0.000092\n", | |
| "0.000021 -0.000122\n", | |
| "... ...\n", | |
| "0.500000 0.000000\n", | |
| "0.500021 0.000000\n", | |
| "\n", | |
| "[24001 rows x 1 columns]" | |
| ] | |
| }, | |
| "execution_count": 98, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "df[[1]]" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": { | |
| "collapsed": true | |
| }, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "metadata": { | |
| "kernelspec": { | |
| "display_name": "Python 2", | |
| "language": "python", | |
| "name": "python2" | |
| }, | |
| "language_info": { | |
| "codemirror_mode": { | |
| "name": "ipython", | |
| "version": 2 | |
| }, | |
| "file_extension": ".py", | |
| "mimetype": "text/x-python", | |
| "name": "python", | |
| "nbconvert_exporter": "python", | |
| "pygments_lexer": "ipython2", | |
| "version": "2.7.10" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 0 | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment