pandas的DataFrame转换为array

读取excel表格数据

import pandas as pd
df = pd.read_excel('w.xlsx')
print(df)
>>> 
    id  feat1  feat2  feat3
0    1      1      0      2
1    2      1      3      5
2    3      4      6      7
3    1      8      1      2
4    3      1      3      5
5    2      3      1    112
6    1    122    123      2
7    2     44     58    997
8    3      4     56     77
9    3     22      2     55
10   2     11     12      0
11   1     66    123     45

转换为array

array = df.values
print(array)
>>>
[[  1   1   0   2]
 [  2   1   3   5]
 [  3   4   6   7]
 [  1   8   1   2]
 [  3   1   3   5]
 [  2   3   1 112]
 [  1 122 123   2]
 [  2  44  58 997]
 [  3   4  56  77]
 [  3  22   2  55]
 [  2  11  12   0]
 [  1  66 123  45]]

你可能感兴趣的:(Python)