teratail header banner
teratail header banner
質問するログイン新規登録

質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.30%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

2回答

939閲覧

標準ライブラリのパケージがエラーがかかり実行ができません。

ytk064

総合スコア0

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

0グッド

0クリップ

投稿2025/02/24 09:42

0

0

実現したいこと

import requests, datetime, time
import pandas as pd
from bs4 import BeautifulSoup
from urllib.parse import urljoin
のインストールで

発生している問題・分からないこと

C:\Users\ytk06\AppData\Local\Temp\ipykernel_7452\2489727194.py:2: DeprecationWarning:
Pyarrow will become a required dependency of pandas in the next major release of pandas (pandas 3.0),
(to allow more performant data types, such as the Arrow string type, and better interoperability with other libraries)
but was not found to be installed on your system.
If this would cause problems for you,
please provide us feedback at https://github.com/pandas-dev/pandas/issues/54466

import pandas as pd

該当のソースコード

webスクレイピングで

1pandasのExcelにOutputする際、 2pd.DataFrame(k_resalt).to_excel('output\Googleアラート(健康経営)'+day+'.xlsx',index=False)

試したこと・調べたこと

  • teratailやGoogle等で検索した
  • ソースコードを自分なりに変更した
  • 知人に聞いた
  • その他
上記の詳細・結果

Excelシートに書き込み方法を教えてください。
pandasなどの更新ができません。
どのようにするか教えてください。

補足

特になし

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

TakaiY

2025/02/24 14:40

質問にあるメッセージはErrorではなく Warning なので、これが出ているのが原因で異常終了することはないはずです。 実際に 質問にある to_excel メソッドが失敗しているのでしょうか? ちなみに、タイトルに「標準ライブラリ」とありますが、どのライブラリを指していますか? 質問に関連するのはどれも標準のものではなさそうですが。
melian

2025/02/24 16:47

to_excel() で指定するファイル名ですが、raw 文字列にしてみてください。(r prefix を付けます) pd.DataFrame(k_resalt).to_excel(r'output\Googleアラート(健康経営)'+day+'.xlsx',index=False) #pd.DataFrame(k_resalt).to_excel('output\Googleアラート(健康経営)'+day+'.xlsx',index=False) また、カレントディレクトリに output というフォルダ(ディレクトリ)が存在していることの確認と、変数 day に Windows のファイル名には使用できない文字(スラッシュ(/)やコロン(:)など)が含まれていないのかどうかも確認してみてください。
ytk064

2025/02/25 06:01

できませんでした。 私がエラー原因は、pandasの更新ではないでしょうか。 更新方法を教えてください。
TakaiY

2025/02/25 06:52

> できませんでした。 なにができなかったのでしょうか? melianさんのコメントの内容も確認されましたか? > 私がエラー原因 先にも書いたとおり、現状の情報にはエラーメッセージは出ていないのでpandasの更新は無意味だと思います。
ytk064

2025/02/25 10:07

ModuleNotFoundError Traceback (most recent call last) Cell In[15], line 1 ----> 1 df.to_excel(r'output\Googleアラート(健康経営)'+day+'.xlsx',index=False) excelのOutputが出来ないです。
TakaiY

2025/02/25 13:14

その、ModuleNotFoundError の内容を省略せずに質問に追記をお願いします。 回答はここでするのではなく、質問に追記してください。質問は編集できます。
meg_

2025/02/25 16:04

> ModuleNotFoundError Traceback (most recent call last) 追加の情報はここではなく質問本文を編集して追記しましょう。そのときにはエラーの詳細も書いてください。
TakaiY

2025/02/26 01:04

エラーメッセージなどの内容は読んでいますか? 回答へのコメントにあるエラーメッセージには ModuleNotFoundError: No module named 'openpyxl' とあります。 openpyxl が無いということですが、インストールされているか確認してみではどうでしょうか。
ytk064

2025/03/04 12:36

今試しに、anacondaの更新作業を実行して丸々3日かかってますが、 anacondaのアップデートで改善されますか。
hiroki-o

2025/03/04 14:01

venvでクリーンな環境を作って試してみてください。 間違ったことは書いていないつもりです。 (皆さん、私の回答が間違っていたら指摘してください)
fiveHundred

2025/03/05 05:19

他の人が言っていることは分かりますか? anacondaが最新版であろうが、「openpyxl」が無いのであれば無意味なのでそれをインストールしてください。
guest

回答2

0

Windows 11、Python 3.13.2、venvで確認しました。

以下の手順とソースにて、エラーも警告も無く実行できました。
質問者さんの環境と比較してみてください。

準備

python -m pip install requests python -m pip install pandas python -m pip install bs4 python -m pip install openpyxl python -m pip list Package Version ------------------ ----------- beautifulsoup4 4.13.3 bs4 0.0.2 certifi 2025.1.31 charset-normalizer 3.4.1 et_xmlfile 2.0.0 idna 3.10 numpy 2.2.3 openpyxl 3.1.5 pandas 2.2.3 pip 24.3.1 python-dateutil 2.9.0.post0 pytz 2025.1 requests 2.32.3 six 1.17.0 soupsieve 2.6 typing_extensions 4.12.2 tzdata 2025.1 urllib3 2.3.0

ソース

import requests, datetime, time import pandas as pd from bs4 import BeautifulSoup from urllib.parse import urljoin k_resalt = [1, 2, 3, 4, 5] day = '20250225' # Gの前の円記号をスラッシュに変更 pd.DataFrame(k_resalt).to_excel('output/Googleアラート(健康経営)'+day+'.xlsx',index=False)

ソースがあるフォルダーに、予めoutputフォルダーを作成してから実行します。
こちらでは、pyarrowが無くても警告は出ませんでした。

投稿2025/02/25 15:12

hiroki-o

総合スコア1440

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ytk064

2025/02/25 22:46

できませんでした。 pandasからExcelsheetにOutputする df.to_excel(r'output\Googleアラート(健康経営)'+day+'.xlsx',index=False) ModuleNotFoundError Traceback (most recent call last) Cell In[6], line 1 ----> 1 df.to_excel(r'output\Googleアラート(健康経営)'+day+'.xlsx',index=False) File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\util\_decorators.py:333, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs) 327 if len(args) > num_allow_args: 328 warnings.warn( 329 msg.format(arguments=_format_argument_list(allow_args)), 330 FutureWarning, 331 stacklevel=find_stack_level(), 332 ) --> 333 return func(*args, **kwargs) File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\core\generic.py:2414, in NDFrame.to_excel(self, excel_writer, sheet_name, na_rep, float_format, columns, header, index, index_label, startrow, startcol, engine, merge_cells, inf_rep, freeze_panes, storage_options, engine_kwargs) 2401 from pandas.io.formats.excel import ExcelFormatter 2403 formatter = ExcelFormatter( 2404 df, 2405 na_rep=na_rep, (...) 2412 inf_rep=inf_rep, 2413 ) -> 2414 formatter.write( 2415 excel_writer, 2416 sheet_name=sheet_name, 2417 startrow=startrow, 2418 startcol=startcol, 2419 freeze_panes=freeze_panes, 2420 engine=engine, 2421 storage_options=storage_options, 2422 engine_kwargs=engine_kwargs, 2423 ) File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\io\formats\excel.py:943, in ExcelFormatter.write(self, writer, sheet_name, startrow, startcol, freeze_panes, engine, storage_options, engine_kwargs) 941 need_save = False 942 else: --> 943 writer = ExcelWriter( 944 writer, 945 engine=engine, 946 storage_options=storage_options, 947 engine_kwargs=engine_kwargs, 948 ) 949 need_save = True 951 try: File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\io\excel\_openpyxl.py:57, in OpenpyxlWriter.__init__(self, path, engine, date_format, datetime_format, mode, storage_options, if_sheet_exists, engine_kwargs, **kwargs) 44 def __init__( 45 self, 46 path: FilePath | WriteExcelBuffer | ExcelWriter, (...) 55 ) -> None: 56 # Use the openpyxl module as the Excel writer. ---> 57 from openpyxl.workbook import Workbook 59 engine_kwargs = combine_kwargs(engine_kwargs, kwargs) 61 super().__init__( 62 path, 63 mode=mode, (...) 66 engine_kwargs=engine_kwargs, 67 ) ModuleNotFoundError: No module named 'openpyxl'
hiroki-o

2025/02/26 12:53

回答した通り、pip install openpyxlしてください。 pandasのExcel機能は、中でopenpyxlを呼んでいるため、必要です。
guest

0

投稿2025/02/24 09:55

Refrain

総合スコア684

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

ytk064

2025/02/24 13:34

すみません、上記URLで試してみましたが、同じ状況でできませんでした。
Refrain

2025/02/24 13:39

pyarrowをインストールした状態でも解消されないということですか? `pip list`などで一覧を出してもらえますか?
ytk064

2025/02/25 22:48

ModuleNotFoundError Traceback (most recent call last) Cell In[6], line 1 ----> 1 df.to_excel(r'output\Googleアラート(健康経営)'+day+'.xlsx',index=False) File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\util\_decorators.py:333, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs) 327 if len(args) > num_allow_args: 328 warnings.warn( 329 msg.format(arguments=_format_argument_list(allow_args)), 330 FutureWarning, 331 stacklevel=find_stack_level(), 332 ) --> 333 return func(*args, **kwargs) File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\core\generic.py:2414, in NDFrame.to_excel(self, excel_writer, sheet_name, na_rep, float_format, columns, header, index, index_label, startrow, startcol, engine, merge_cells, inf_rep, freeze_panes, storage_options, engine_kwargs) 2401 from pandas.io.formats.excel import ExcelFormatter 2403 formatter = ExcelFormatter( 2404 df, 2405 na_rep=na_rep, (...) 2412 inf_rep=inf_rep, 2413 ) -> 2414 formatter.write( 2415 excel_writer, 2416 sheet_name=sheet_name, 2417 startrow=startrow, 2418 startcol=startcol, 2419 freeze_panes=freeze_panes, 2420 engine=engine, 2421 storage_options=storage_options, 2422 engine_kwargs=engine_kwargs, 2423 ) File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\io\formats\excel.py:943, in ExcelFormatter.write(self, writer, sheet_name, startrow, startcol, freeze_panes, engine, storage_options, engine_kwargs) 941 need_save = False 942 else: --> 943 writer = ExcelWriter( 944 writer, 945 engine=engine, 946 storage_options=storage_options, 947 engine_kwargs=engine_kwargs, 948 ) 949 need_save = True 951 try: File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\io\excel\_openpyxl.py:57, in OpenpyxlWriter.__init__(self, path, engine, date_format, datetime_format, mode, storage_options, if_sheet_exists, engine_kwargs, **kwargs) 44 def __init__( 45 self, 46 path: FilePath | WriteExcelBuffer | ExcelWriter, (...) 55 ) -> None: 56 # Use the openpyxl module as the Excel writer. ---> 57 from openpyxl.workbook import Workbook 59 engine_kwargs = combine_kwargs(engine_kwargs, kwargs) 61 super().__init__( 62 path, 63 mode=mode, (...) 66 engine_kwargs=engine_kwargs, 67 ) ModuleNotFoundError: No module named 'openpyxl' pd.DataFrame(k_resalt).to_excel('output\Googleアラート(健康経営)'+day+'.xlsx',index=False) <>:1: SyntaxWarning: invalid escape sequence '\G' <>:1: SyntaxWarning: invalid escape sequence '\G' C:\Users\ytk06\AppData\Local\Temp\ipykernel_15872\1636946245.py:1: SyntaxWarning: invalid escape sequence '\G' pd.DataFrame(k_resalt).to_excel('output\Googleアラート(健康経営)'+day+'.xlsx',index=False) C:\Users\ytk06\AppData\Local\Temp\ipykernel_15872\1636946245.py:1: SyntaxWarning: invalid escape sequence '\G' pd.DataFrame(k_resalt).to_excel('output\Googleアラート(健康経営)'+day+'.xlsx',index=False) --------------------------------------------------------------------------- ModuleNotFoundError Traceback (most recent call last) Cell In[16], line 1 ----> 1 pd.DataFrame(k_resalt).to_excel('output\Googleアラート(健康経営)'+day+'.xlsx',index=False) File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\util\_decorators.py:333, in deprecate_nonkeyword_arguments.<locals>.decorate.<locals>.wrapper(*args, **kwargs) 327 if len(args) > num_allow_args: 328 warnings.warn( 329 msg.format(arguments=_format_argument_list(allow_args)), 330 FutureWarning, 331 stacklevel=find_stack_level(), 332 ) --> 333 return func(*args, **kwargs) File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\core\generic.py:2414, in NDFrame.to_excel(self, excel_writer, sheet_name, na_rep, float_format, columns, header, index, index_label, startrow, startcol, engine, merge_cells, inf_rep, freeze_panes, storage_options, engine_kwargs) 2401 from pandas.io.formats.excel import ExcelFormatter 2403 formatter = ExcelFormatter( 2404 df, 2405 na_rep=na_rep, (...) 2412 inf_rep=inf_rep, 2413 ) -> 2414 formatter.write( 2415 excel_writer, 2416 sheet_name=sheet_name, 2417 startrow=startrow, 2418 startcol=startcol, 2419 freeze_panes=freeze_panes, 2420 engine=engine, 2421 storage_options=storage_options, 2422 engine_kwargs=engine_kwargs, 2423 ) File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\io\formats\excel.py:943, in ExcelFormatter.write(self, writer, sheet_name, startrow, startcol, freeze_panes, engine, storage_options, engine_kwargs) 941 need_save = False 942 else: --> 943 writer = ExcelWriter( 944 writer, 945 engine=engine, 946 storage_options=storage_options, 947 engine_kwargs=engine_kwargs, 948 ) 949 need_save = True 951 try: File ~\AppData\Local\Programs\Python\Python312\Lib\site-packages\pandas\io\excel\_openpyxl.py:57, in OpenpyxlWriter.__init__(self, path, engine, date_format, datetime_format, mode, storage_options, if_sheet_exists, engine_kwargs, **kwargs) 44 def __init__( 45 self, 46 path: FilePath | WriteExcelBuffer | ExcelWriter, (...) 55 ) -> None: 56 # Use the openpyxl module as the Excel writer. ---> 57 from openpyxl.workbook import Workbook 59 engine_kwargs = combine_kwargs(engine_kwargs, kwargs) 61 super().__init__( 62 path, 63 mode=mode, (...) 66 engine_kwargs=engine_kwargs, 67 ) ModuleNotFoundError: No module named 'openpyxl'
Refrain

2025/02/26 10:01

すみません、`ModuleNotFoundError: No module named 'openpyxl'`と出ている時点で別のエラーなのでは…? openpyxlはインストールされていますか? また、`pip list`の結果はどうなりますか?
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだベストアンサーが選ばれていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.30%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問