Sufficiency Economy
Group Blog
 
All blogs
 
Python : Machine Learning [4]

วันนี้เรียน บทที่ 6,7 สอนเกี่ยวกับ การกรองข้อมูล การเรียงข้อมูล การเพิ่มcolumn
กรองข้อมูล คือการกำหนด condition ใน loc แล้วเลือกว่าจะให้แสดง column ใดบ้าง
ส่วน reset_index() เมื่อต้องการให้เรียงจาก 0 
df1=df.loc[df["MILES*"] >10,["MILES*"]].head(n=5).reset_index()
มีการใช้ isin ด้วย ดูรูปข้างล่าง
ถ้ามี 2 condition ก็ให้ใช้เครื่องหมาย & มาเชื่อม

การเรียงข้อมูล
ใช้ sort_values
df.sort_values(by=["START*","MILES*"],ascending=[True,False]).head(n=5)

การเพิ่ม column
ต้องใช้ numpy มาช่วย ประมาณนี้
import numpy as np
df["my_cat"] = np.where(df["MILES*"]>5,"Long","Short")
df.head(n=3)

ตอนแรกดูง่ายๆ หลังๆเริ่มสับสน 2





 


Create Date : 16 สิงหาคม 2563
Last Update : 16 สิงหาคม 2563 15:05:43 น. 0 comments
Counter : 622 Pageviews.

ชื่อ :
Comment :
  *ใช้ code html ตกแต่งข้อความได้เฉพาะสมาชิก
 

wink99_th
Location :
พิษณุโลก Thailand

[Profile ทั้งหมด]

ฝากข้อความหลังไมค์
Rss Feed
Smember
ผู้ติดตามบล็อก : 8 คน [?]




New Comments
Friends' blogs
[Add wink99_th's blog to your web]
Links
 

 Pantip.com | PantipMarket.com | Pantown.com | © 2004 BlogGang.com allrights reserved.