私はこの "The Year The Year For Ending 2015"を解析し、datetime libを使用して2015-12-31に変換しようとしています。私はどのように分割して日付を変換するのですか?私のプログラムは、複数のシートを持つExcelファイルを探し、それらを1つに結合します。しかし、今、日付の列を追加する必要がありますが、私はそれがセルに完全な値を書き込むことができます。ですから、私のデータ列は現在、すべての行に「For The Year Ending 12月31、2015」があります。文字列を解析し、Pythonを使って日付を変換する
ありがとうございます!
ここでは現在動作しているコードブロックを示します。皆さんありがとう!変化する可能性のあるテキストを考慮して編集されています。
if rx > (options.startrow-1):
ws.write(rowcount, 0, sheet.name)
date_value = sheet.cell_value(4,0)
s = date_value.split(" ")
del s[-1]
del s[-1]
del s[-1]
string = ' '.join(s)
d = datetime.strptime(date_value, string + " %B %d, %Y")
result = datetime.strftime(d, '%Y-%m-%d')
ws.write(rowcount, 9, result)
for cx in range(sheet.ncols):
は、あなたが完全なコード含まれてあなたがこれまで試みられてきたものを共有してください。 –
これを見てください。私はこれが役立つことを願っていますhttp://stackoverflow.com/questions/2265357/parse-date-string-and-change-format?noredirect=1&lq=1 – Ehsan