开始使用免费开始使用

对边界列做 explode

您已经成功转换了类列表的列,但对所需步骤并不满意。您希望用更简便的方法得到相同的重塑后 DataFrame。

您想起了关于对类列表列进行 explode 的内容,并将采用一种新策略。

同一个 DataFrame obesity 已在您的会话中可用。它包含 countryperc_obesity,以及 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)
编辑并运行代码