datetime 函式庫與 Split 函式

使用 Python 進行財務預測

Victoria Clark

CGMA Financial Analyst

衝突類型

日期:09/10/2018

地區格式差異

  • 日-月-年
  • 月-日-年

標點符號差異

  • dd-mm-yy
  • dd/mm/yyyy

財務報表

使用 Python 進行財務預測

datetime 函式

# Import datetime module
from datetime import datetime

datetime.strptime(date_string, format)

12-25-2000 --> %m-%d-%Y'

datetime.strptime('12-25-2000',
                  '%m-%d-%Y')

print(dt_object.month)
12

日期

使用 Python 進行財務預測

使用 split() 函式

  • split() 函式
date = '14/02/2018'

# 使用 / 分割日期字串並指派給具名變數 day, month, year = date.split('/')
print(year)
2018
使用 Python 進行財務預測

一起來練習吧!

使用 Python 進行財務預測

Preparing Video For Download...