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

การเข้าถึง Bounding Box

ทวีตส่วนใหญ่ที่มีข้อมูลตำแหน่งในระดับพิกัดมักอยู่ในรูปแบบของ bounding box ซึ่งเป็นชุดพิกัดลองจิจูด/ละติจูด 4 จุดที่ระบุพื้นที่ที่ผู้ใช้อาจอยู่ โดย bounding box จะอยู่ใน field place ของ JSON ของ Twitter

ชุดข้อมูลถูกโหลดให้แล้วในรูปแบบ DataFrame ชื่อ tweets_sotu

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

การวิเคราะห์ข้อมูลโซเชียลมีเดียด้วย Python

ดูคอร์ส

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

  • เติมฟังก์ชัน getBoundingBox() ให้สมบูรณ์โดยเข้าถึงค่า coordinates ภายใน dictionary ของ bounding box
  • นำฟังก์ชัน getBoundingBox() ไปใช้กับคอลัมน์ที่เหมาะสมใน DataFrame tweets_sotu

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

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

def getBoundingBox(place):
    """ Returns the bounding box coordinates."""
    return place[____][____]

# Apply the function which gets bounding box coordinates
bounding_boxes = tweets_sotu[____].apply(getBoundingBox)

# Print out the first bounding box coordinates
print(bounding_boxes.values[0])
แก้ไขและรันโค้ด