การพล็อตตำแหน่งของไก่
ตอนนี้จะสร้าง 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()