เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

Extracting longitude and latitude

A DataFrame named df has been pre-loaded for you. Complete the code to extract longitude and latitude to new, separate columns.

แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร

Visualizing Geospatial Data in Python

ดูคอร์ส

คำแนะนำการฝึกหัด

  • Print the first few rows with print() and df.head().
  • Use a list comprehension to extract latitude to a new column called lat.
  • Use a list comprehension to extract longitude to a new column called lng.
  • Print the first few rows with print() and df.head() again to confirm the new columns.

แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ

ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์

# 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())
แก้ไขและรันโค้ด