2017-01-19 6 views
1

の呼び出し中:例外TypeError私はいくつかのテーブルを持つファイルと、このエラーを取得維持エクセルを開くしようとしているpandas.ExcelFile

TypeError: unsupported operand type(s) for <<: 'str' and 'int' 

は、これは私のコードです:また

import pandas as pd 
from pathlib import Path 
import sys 

def file_lister(path, extension=None): 
    if extension is None: 
     return list(path.glob('*')) 
    else: 
     return list(path.glob('*' + extension)) 


fpath = Path().resolve().parent 
fname = 'Accounts 2017 varios.xlsx' 

try: 
    io = list(fpath.glob(fname))[0] 
except IndexError: 
    file_list = file_lister(fpath, 'xlsx') 
    raise Warning(('{} not founded. Available files:' + '\n\t{}' * len(
        file_list)).format(fname, *[file for file in file_list])) 

encoding = 'latin-1' 

xl = pd.ExcelFile(io.open(encoding=encoding)) 

、私が手同じエラーを使用して:

pd.read_excel(io.open(encoding=sys.getfilesystemencoding())) 

私はopen()でファイルを正常に開くことができます。

私は窓の8.1

任意の手がかりでPython 3.4とパンダ0.16.2を使用していますか?

+1

を例外が発生したライン何で? – EndermanAPM

+0

open()を使用するときに、「b」を追加してExcelファイルをバイナリファイルに指定できますか?たとえば、 'io.open(encoding = encoding、 'rb')' – SSC

+0

io.open( 'rb')が働いてくれてありがとう – Mstaino

答えて

1

[OK]を、次の二つのソリューションが働いた:

xl = pd.ExcelFile(str(io)) 

そして:

xl = pd.ExcelFile(io.open('rb')) 

(1秒のためのSSCのおかげで)

関連する問題