pandas                
            パンダのDataFrameにファイルを読み込む
        
        
            
    サーチ…
DataFrameにテーブルを読み込む
ヘッダー、フッター、行名、および索引列を含む表ファイル:
ファイル:table.txt
This is a header that discusses the table file
to show space in a generic table file
index  name     occupation
1      Alice    Salesman
2      Bob      Engineer
3      Charlie  Janitor  
This is a footer because your boss does not understand data files
コード:
import pandas as pd
# index_col=0 tells pandas that column 0 is the index and not data 
pd.read_table('table.txt', delim_whitespace=True, skiprows=3, skipfooter=2, index_col=0)
出力:
          name occupation
index
1        Alice   Salesman
2          Bob   Engineer
3      Charlie    Janitor
行名またはインデックスのない表ファイル:
ファイル:table.txt
Alice    Salesman
Bob      Engineer
Charlie  Janitor 
コード:
import pandas as pd 
pd.read_table('table.txt', delim_whitespace=True, names=['name','occupation'])
出力:
      name occupation
0    Alice   Salesman
1      Bob   Engineer
2  Charlie    Janitor
すべてのオプションは、 ここのpandasドキュメントにあります
CSVファイルを読む
コンマではなくセミコロンで区切られたヘッダー付きデータ
ファイル:table.csv
index;name;occupation
1;Alice;Saleswoman
2;Bob;Engineer
3;Charlie;Janitor
コード:
import pandas as pd
pd.read_csv('table.csv', sep=';', index_col=0)
出力 :
          name occupation
index
1        Alice   Salesman
2          Bob   Engineer
3      Charlie    Janitor
区切り記号として行名または索引およびカンマのない表
ファイル:table.csv
Alice,Saleswoman
Bob,Engineer
Charlie,Janitor
コード:
import pandas as pd 
pd.read_csv('table.csv', names=['name','occupation'])
出力:
      name occupation
0    Alice   Salesman
1      Bob   Engineer
2  Charlie    Janitor
 read_csvドキュメントページに詳しい説明があります
Googleのスプレッドシートデータをpandasデータフレームに収集する
場合によっては、Googleスプレッドシートからデータを収集する必要があります。 gspreadとoauth2clientライブラリを使用してGoogleスプレッドシートからデータを収集できます。データを収集する例を次に示します。
コード:
from __future__ import print_function
import gspread
from oauth2client.client import SignedJwtAssertionCredentials
import pandas as pd
import json
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('your-authorization-file.json', scope)
gc = gspread.authorize(credentials)
work_sheet = gc.open_by_key("spreadsheet-key-here")
sheet = work_sheet.sheet1
data = pd.DataFrame(sheet.get_all_records()) 
print(data.head())
Modified text is an extract of the original Stack Overflow Documentation
        ライセンスを受けた CC BY-SA 3.0
        所属していない Stack Overflow