pythonのpandasで、 フォルダ内にある全てのエクセルファイルを1つのエクセルシートにまとめたいと思い、試したのですがエラーになってしまいます。
解決案をご教授ください。
フォルダのディレクトリー
/Users/macbookpro/OneDrive/7月以降競馬アプリ/スクレイピング
試したコード
python
1 2import os 3import glob 4import pandas as pd 5 6# dataフォルダ内にあるxlsxファイルの一覧を取得 7files = glob.glob("スクレイピング/*.xlsx") 8 9# 全てのxlsxファイルを読み込み、dictに入れる(keyはファイル名) 10dfs = {} 11for file in files: 12 dfs[os.path.basename(file)] = pd.read_xlsx(file, header=None) 13 14# PANEL作成 15pf = pd.Panel(dfs) 16#xlsxファイル(max/min)を生成 17pf.max(axis=0).to_xlsx("max.xlsx", index=None, header=None) 18pf.min(axis=0).to_xlsx("min.xlsx", index=None, header=None)
発生したエラー
python
1ttributeError Traceback (most recent call last) 2<ipython-input-14-bd712538e3b5> in <module>() 3 14 pf = pd.Panel(dfs) 4 15 #xlsxファイル(max/min)を生成 5---> 16 pf.max(axis=0).to_xlsx("max.xlsx", index=None, header=None) 6 17 pf.min(axis=0).to_xlsx("min.xlsx", index=None, header=None) 7 8~/anaconda3/lib/python3.6/site-packages/pandas/core/generic.py in stat_func(self, axis, skipna, level, numeric_only, **kwargs) 9 6340 skipna=skipna) 10 6341 return self._reduce(f, name, axis=axis, skipna=skipna, 11-> 6342 numeric_only=numeric_only) 12 6343 13 6344 return set_function_name(stat_func, name, cls) 14 15~/anaconda3/lib/python3.6/site-packages/pandas/core/panel.py in _reduce(self, op, name, axis, skipna, numeric_only, filter_type, **kwds) 16 1127 17 1128 axes = self._get_plane_axes(axis_name) 18-> 1129 if result.ndim == 2 and axis_name != self._info_axis_name: 19 1130 result = result.T 20 1131 21 22AttributeError: 'float' object has no attribute 'ndim'

あなたの回答
tips
プレビュー