サイズが非常に大きいExcelブックがあります。ここで私は がPythonのpandasを使っているのが好きです。私はPython 3.4を実行しています。パンダを使用してExcelワークブック全体のデータを変更する
- パンダでブックを開きます。別の何か1つのセル内
- 変更値 - 例えば、現在「ジェーン・ドウ」 私は全体を選択したい念頭に「ボブ・スミス」
- ベアに命名されたセルA2の文字列を変更 1枚だけではなく、ワークブック。私の目標は、複数の一括変更を行うことです。
ここでは私のコードです:答えから
import pandas as pd
xls = pd.ExcelFile('Data.xlsx')
df = xls.parse('Data')
df1 = df.replace('Jane Doe', 'Bob Smith')
編集:
アイハン、あなたの応答を親切にありがとうございました。 ----> 1つのdf =のPD)(中
fs = pd.read_excel('filename.xlsx', sheetname=None)
てAssertionErrorトレースバック(最新の呼び出しの最後) :
私はあなたの方法を使用してデータをロードしようとすると、私は次のエラーを取得します。 read_excel( "Data.xlsx")
/home/minx/anaconda3/lib/python3.4/site-packages/pandas/io/excel.py in read_excel(io, sheetname, header, skiprows, skip_footer, index_col, names, parse_cols, parse_dates, date_parser, na_values, thousands, convert_float, has_index_names, converters, engine, squeeze, **kwds)
167 """
168 if not isinstance(io, ExcelFile):
--> 169 io = ExcelFile(io, engine=engine)
170
171 return io._parse_excel(
/home/minx/anaconda3/lib/python3.4/site-packages/pandas/io/excel.py in __init__(self, io, **kwds)
216 self.book = xlrd.open_workbook(file_contents=data)
217 else:
--> 218 self.book = xlrd.open_workbook(io)
219 elif engine == 'xlrd' and isinstance(io, xlrd.Book):
220 self.book = io
/home/minx/.local/lib/python3.4/site-packages/xlrd/__init__.py in open_workbook(filename, logfile, verbosity, use_mmap, file_contents, encoding_override, formatting_info, on_demand, ragged_rows)
420 formatting_info=formatting_info,
421 on_demand=on_demand,
--> 422 ragged_rows=ragged_rows,
423 )
424 return bk
/home/minx/.local/lib/python3.4/site-packages/xlrd/xlsx.py in open_workbook_2007_xml(zf, component_names, logfile, verbosity, use_mmap, formatting_info, on_demand, ragged_rows)
792 x12sheet = X12Sheet(sheet, logfile, verbosity)
793 heading = "Sheet %r (sheetx=%d) from %r" % (sheet.name, sheetx, fname)
--> 794 x12sheet.process_stream(zflo, heading)
795 del zflo
796 comments_fname = 'xl/comments%d.xml' % (sheetx + 1)
/home/minx/.local/lib/python3.4/site-packages/xlrd/xlsx.py in own_process_stream(self, stream, heading)
532 elem.clear() # destroy all child elements (cells)
533 elif elem.tag == U_SSML12 + "dimension":
--> 534 self.do_dimension(elem)
535 elif elem.tag == U_SSML12 + "mergeCell":
536 self.do_merge_cell(elem)
/home/minx/.local/lib/python3.4/site-packages/xlrd/xlsx.py in do_dimension(self, elem)
566 # print >> self.logfile, "dimension: ref=%r" % ref
567 last_cell_ref = ref.split(':')[-1] # example: "Z99"
--> 568 rowx, colx = cell_name_to_rowx_colx(last_cell_ref)
569 self.sheet._dimnrows = rowx + 1
570 self.sheet._dimncols = colx + 1
/home/minx/.local/lib/python3.4/site-packages/xlrd/xlsx.py in cell_name_to_rowx_colx(cell_name, letter_value)
89 else: # start of row number; can't be '0'
90 colx = colx - 1
---> 91 assert 0 <= colx < X12_MAX_COLS
92 break
93 except KeyError:
AssertionError:
だから何試してみましたが、どうしてうまくいかないのですか? –
ok、なぜそれは機能しませんか? –
うーん、なぜそれがうまくいかないのか分かっていたら、私はその質問をしないだろう。 – minx