List of dictionaries
คุณได้รับข้อมูลอะโวคาโดชุดใหม่ปี 2019 และต้องการสร้าง DataFrame จากข้อมูลนี้โดยใช้วิธี list of dictionaries ซึ่งจะประมวลผลข้อมูลทีละแถว
| date | small_sold | large_sold |
|---|---|---|
| "2019-11-03" | 10376832 | 7835071 |
| "2019-11-10" | 10717154 | 8561348 |
pandas ถูก import ไว้แล้วในชื่อ pd
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การจัดการข้อมูลด้วย pandas
คำแนะนำการฝึกหัด
- สร้าง list of dictionaries จากข้อมูลใหม่ โดยตั้งชื่อว่า
avocados_list - แปลง list ดังกล่าวให้เป็น DataFrame ชื่อ
avocados_2019 - แสดงผล DataFrame ที่สร้างขึ้น
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Create a list of dictionaries with new data
avocados_list = [
{____: ____, ____: ____, ____: ____},
{____: ____, ____: ____, ____: ____},
]
# Convert list into DataFrame
avocados_2019 = ____
# Print the new DataFrame
____