從清單組成的字典
建立 pandas DataFrame 的常見方式之一,是先逐一定義每個欄位。當每個欄位的資料已經存在於清單或 NumPy 陣列中特別好用。在本練習中,你會把多個清單中的資料組合成一個 Python 字典,接著建立一個 pandas 的 DataFrame。
以下清單已載入到你的工作環境:
date:每次鳥擊事件的日期,為字串height:發生鳥擊時的高度(英尺)speed:發生鳥擊時的速度(節)engine:每次鳥擊涉及的引擎型式airport:與每次鳥擊相關的機場damage:飛機受損的嚴重程度
本練習屬於課程
給 MATLAB 使用者的 Python
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create a dictionary from lists
strikes_dict = {'Date' : date,
'Speed' : ____,
'____' : height,
'____' : ____,
'____' : ____,
____ : airport}
# Print dictionary
print(strikes_dict)