解析簡單日期
pandas 不會自動推斷欄位是 datetime 資料;除非你特別指定,否則會把它們當成物件或字串資料。當日期時間採用標準格式時,正確建模非常容易──你可以在 read_excel() 中使用 parse_dates 參數,指定要把哪些欄位讀成 datetime 資料。
New Developer Survey 的回覆中有一些時間戳記很容易解析。在這個練習中,你要確保它們的資料型別正確。
pandas 已以 pd 載入。
本練習屬於課程
使用 pandas 的精實資料導入
練習說明
- 載入
fcc_survey.xlsx,並確保Part1StartTime欄位會被解析為 datetime 資料。 - 檢視
survey_data.Part1StartTime的前幾個值,確認其中包含的是 datetime。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Load file, with Part1StartTime parsed as datetime data
survey_data = pd.read_excel("fcc_survey.xlsx",
____)
# Print first few values of Part1StartTime
print(survey_data.Part1StartTime.____)