提取经度和纬度
名为 df 的 DataFrame 已为您预加载。请补全代码,将经度和纬度提取到新的「分开」列中。
本练习是课程的一部分
在 Python 中可视化地理空间数据
练习说明
- 使用
print()和df.head()打印前几行。 - 使用列表推导将纬度提取到名为
lat的新列中。 - 使用列表推导将经度提取到名为
lng的新列中。 - 再次使用
print()和df.head()打印前几行,确认新列已创建。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# print the first few rows of df
print(df.head())
# extract latitude to a new column: lat
df['lat'] = [loc[_____] for loc in df.Location]
# extract longitude to a new column: lng
df['lng'] = [loc[_____] for loc in df.Location]
# print the first few rows of df again
print(df.head())