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

การพล็อตตำแหน่งของไก่

ตอนนี้จะสร้าง scatterplot เพื่อแสดงตำแหน่งของไก่ในเมืองแนชวิลล์กัน!

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

การแสดงผลข้อมูลเชิงภูมิศาสตร์ด้วย Python

ดูคอร์ส

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

  • path ของชุดข้อมูลไก่อยู่ในตัวแปร chickens_path ใช้ฟังก์ชัน read_csv ของ pandas เพื่อโหลดข้อมูลลงใน DataFrame ชื่อ chickens
  • ใช้ฟังก์ชัน .head() เพื่อดูแถวแรก ๆ ของข้อมูล
  • จากนั้นเพิ่มอาร์กิวเมนต์ x และ y ใน plt.scatter() เพื่อพล็อตตำแหน่งของไก่ในแนชวิลล์ โดยใช้ค่าเริ่มต้นของ marker และสี
  • แสดงกราฟโดยใช้ plt.show()

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

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

# Import pandas and matplotlib.pyplot using their customary aliases
import pandas as pd
import matplotlib.pyplot as plt

# Load the dataset
chickens = pd.____(chickens_path)

# Look at the first few rows of the chickens DataFrame
print(chickens.____())

# Plot the locations of all Nashville chicken permits
plt.scatter(x = chickens.____, y = chickens.____)

# Show the plot
plt.show()
แก้ไขและรันโค้ด