Pythonで文字列を日付型に変える方法(ついでにPandasの場合とも比較)2023/2/22 / 1 min readView more blogs with the tag python, View more blogs with the tag pandasTable of Contents#はじめに#方法はじめに Pythonで文字列を日付型に変える方法です。ついでにPandasの場合とも比較しています。 方法 import datetime t = 'May 26, 2022't2 = datetime.datetime.strptime(t, '%b %d, %Y')t3 = datetime.date(t2.year, t2.month, t2.day)# Output -> 2022-05-26 # dfの場合import pandas as pdpd.to_datetime(df['date'], format='%b %d, %Y')# Output -> 2022-05-26関連記事2026/8/16pandas前処理まとめ|結合・エンコーディング・欠損の右詰め・単語頻度2026/8/9Google Colaboratory活用まとめ|Drive連携・GPU・MeCab・Selenium2023/7/20SQLAlchemy2.0以降を使ってread_sqlする方法2023/5/17indexメソッドを利用した複数条件でdfの行を削除する2023/4/26Pandasのテーブルをまとめて一つのエクセルに出力したいときこの記事を書いた人barorin公認会計士会計とITの二足のわらじで働く公認会計士です。Pythonを中心に、会計・監査の実務で実際に使っているコードや、Ubuntu・Raspberry Piの設定メモを書いています。Find me onGithubFedibirdTwitterBuyMeACoffeeRSS