0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Pythonでのツール作成時に困ったこと①

Last updated at Posted at 2023-08-14

前回初めてPythonでのツールを作成することができました!
いろんなQIITAの記事やサイトを参考させていただいたおかげです。

今回は、Pythonのツール作成時に実際に起きた間違いをまとめてみました。

①ファイルパス
文字列を組み合わせてファイルパスを作ろうとした際に、フォルダ名の部分がファイル名と判断されず、ファイル名が「●●(本来フォルダ名)¥▲▲(本来のファイル名)」となったファイルが出力された。
Windowsのファイルパスは「/」だか、Pythonでは「/」はエスケープとして判断されるそうで
フォルダ名と判断されなかった。
解決方法として、os.path.joinにしたらファイルパスと判断されました。

②DateFrameの型
DateFrameを二つ用意して、結合しようとしたところ、同じフォルダ名をキーにしていたのにエラーとなってしまった。
同じファイル名でも、typeがそれぞれ別でDateFrameに格納されていたために、キーが不一致と判断されてしまっていた。
結合の前にDateFrameの型を同じになるようにastype()で変換した。

③関数の位置
独自の関数を作成したところ、エラーとなってしまう。
独自の関数は、関数の定義を本体の処理の前に書いておかないといけないということが漏れていた。
解決策として、関数の定義を本体の処理の前にしたら、正常に動いた。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?