对Python中DataFrame按照行遍历的方法
在做分类模型时候,需要在DataFrame中按照行获取数据以便于进行训练和测试。
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])
实验结果:
/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
相关推荐
81510295 2020-11-17
roamer 2020-10-29
listep 2020-09-11
Tristahong 2020-08-24
三石 2020-08-23
QianYanDai 2020-08-16
Johnson0 2020-07-28
mmmjyjy 2020-07-16
santiago00 2020-07-11
QianYanDai 2020-07-05
QianYanDai 2020-07-05
jiahaohappy 2020-06-21
QianYanDai 2020-06-16
Oeljeklaus 2020-05-29
zhangxiaojiakele 2020-05-25
人家 2020-05-17
jzlixiao 2020-05-15
柠檬班 2020-05-16
jiahaohappy 2020-05-12