在作分類模型時候,須要在DataFrame中按照行獲取數據以便於進行訓練和測試。html
import pandas as pd dict=[[1,2,3,4,5,6],[2,3,4,5,6,7],[3,4,5,6,7,8],[4,5,6,7,8,9],[5,6,7,8,9,10]] data=pd.DataFrame(dict) print(data) for indexs in data.index: print(data.loc[indexs].values[0:-1])
實驗結果:python
/usr/bin/python3.4 /home/ubuntu/PycharmProjects/pythonproject/findgaoxueya/test.py 0 1 2 3 4 5 0 1 2 3 4 5 6 1 2 3 4 5 6 7 2 3 4 5 6 7 8 3 4 5 6 7 8 9 4 5 6 7 8 9 10 [1 2 3 4 5] [2 3 4 5 6] [3 4 5 6 7] [4 5 6 7 8] [5 6 7 8 9] Process finished with exit code 0
詳情 http://pandas.pydata.org/pandas-docs/stable/cookbook.html ubuntu