#範例3-4:從DataFrame資料裡面取出num_children vs num_pets來繪scatter圖 #散佈圖scatter指令: df.plot(kind='scatter',x='...',y='..') #柱狀圖bar指令: df.plot(kind='bar',x='...',y='..') import pandas as pd df = pd.DataFrame({ 'name':['john','mary','peter','jeff','bill','lisa','jose'], 'age':[23,78,22,19,45,33,20], 'gender':['M','F','M','M','M','F','M'], 'state':['california','dc','california','dc','california','texas','texas'], 'num_children':[2,0,0,3,2,1,4], 'num_pets':[5,1,0,5,2,2,3] }) #顯示每人寵物數量 df.plot(kind='scatter',x='name',y='num_pets',color='red') #顯示年齡分佈 df.plot(kind='scatter', x='name', y='age',color='blue') #顯示每人的小孩數量(scatter) df.plot(kind='scatter',x='name', y='num_children',color='green') #顯示每人的小孩數量(柱狀圖 bar) df.plot(kind='bar',x='name',y='num_children',color='green')