Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. 1. 如何將所有欄位顯示出來?
  2. pd.set_option('display.max_columns', None)
  3.  
  4. 2. 如何移除欄位?
  5. 單欄位
  6. train = train.drop(['欄位'], axis=1)
  7. 多欄位
  8. train = train.drop(['欄位1','欄位2'], axis=1)
  9.  
  10. 3. 如何查看欄位的型別?
  11. train.dtypes
  12.  
  13. 4. 如何轉換欄位型別?
  14. 以 int64 轉換為 str
  15. feature['欄位1'] = feature['欄位1'].apply(str)
  16. feature['欄位1'] = featuer['欄位1'].astype(str)
  17.  
  18. 5. 如何觀察特徵之間的關聯性?
  19. feature.corr() #型別需為int
  20.  
  21. 6. 如何畫散佈圖?
  22. import matplotlib.pyplot as plt #匯入相關套件
  23. plt.scatter(x, y)
  24. plt.show() #顯示圖
  25.  
  26. 7. 如何將同資料型態選取出來?
  27. int_type = train.select_dtypes(include=['int32','int64','float64'])
  28. cat_type = train.select_dtypes(include=['object'])
  29.  
  30. 8. 如何將統計出空值的數量排序?
  31. train.isnull().sum().sort_values(ascending=False)
  32.  
  33. 9. 如何取出欄位?
  34. y = train.pop('欄位')
  35.  
  36. 10. 如何計算出現次數?
  37. y['欄位'].value_counts()
  38.  
  39. 11. 如何將欄位設定為索引?
  40. #會將第一列設定為索引
  41. test = pd.read_csv('Desktop/house-prices-advanced-regression-techniques/test.csv', index_col = 0)
  42.  
  43. 12.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement