開始使用免費開始

展開界線

你已經成功轉換了類清單的欄位,但對於所需步驟並不滿意。你想找一個更簡單的方法,產生相同的重塑後 DataFrame。

你想起先前學過如何展開類清單的欄位,現在要套用一個新策略。

同一個 DataFrame obesity 已在你的工作階段中可用。它包含 countryperc_obesity,以及 bounds 欄位;bounds 提供同一國家不同地區可見的最小與最大值。

本練習屬於課程

使用 pandas 重塑資料

檢視課程

練習說明

  • 將 DataFrame obesity 中的類清單欄位 bounds 轉換為每個元素各佔一列。
  • 重設索引以移除舊索引,調整得到的 DataFrame。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Transform the list-like column named bounds  
obesity_explode = ____.____(____)

# Modify obesity_explode by resetting the index 
obesity_explode.____(drop=____, inplace=____)

# Print obesity_explode
print(obesity_explode)
編輯並執行程式碼