我希望将以下数据帧转换为列表

时间:2017-04-19 23:58:07

标签: list pandas dataframe

   Sl No        Vertical  Verticale Code Org Work Location  \
0      1.0              IT               5         New Delhi   
1      2.0              IT               5            Raipur   
2      3.0  Infrastructure               7        Coimbatore   
3      4.0         Telecom               3           Chennai   
4      5.0         Telecom               3         Ahmedabad   
5      6.0              IT               5           Chennai   
6      7.0              IT               5           Chennai   
7      8.0     IT Products               6         Bangalore   
8      9.0              IT               5           Chennai   
9     10.0              IT               5           Chennai   
10    11.0         Telecom               3         Bangalore   
11    12.0              IT               5            Mysore   
12    13.0     IT Products               6       Navi Mumbai   
13    14.0         Telecom               3         Bangalore   
14    15.0  Infrastructure               7           Chennai   
15    16.0              IT               5           Chennai   
16    17.0              IT               5           Chennai   
17    18.0  Infrastructure               7        Coimbatore   
18    19.0         Telecom               3           Chennai   
19    20.0         Telecom               3         Bangalore   
20    21.0         Telecom               3         Bengalore   
21    22.0              IT               5           Chennai 

1 个答案:

答案 0 :(得分:2)

取决于您是否需要平面列表或嵌套列表。

嵌套列表

df.values.tolist()

[[0, 1.0, 'IT', '5', 'New', 'Delhi', nan, nan],
 [1, 2.0, 'IT', '5', 'Raipur', nan, nan, nan],
 [2, 3.0, 'Infrastructure', '7', 'Coimbatore', nan, nan, nan],
 [3, 4.0, 'Telecom', '3', 'Chennai', nan, nan, nan],
 [4, 5.0, 'Telecom', '3', 'Ahmedabad', nan, nan, nan],
 [5, 6.0, 'IT', '5', 'Chennai', nan, nan, nan],
 [6, 7.0, 'IT', '5', 'Chennai', nan, nan, nan],
 [7, 8.0, 'IT', 'Products', '6', 'Bangalore', nan, nan],
 [8, 9.0, 'IT', '5', 'Chennai', nan, nan, nan],
 [9, 10.0, 'IT', '5', 'Chennai', nan, nan, nan],
 [10, 11.0, 'Telecom', '3', 'Bangalore', nan, nan, nan],
 [11, 12.0, 'IT', '5', 'Mysore', nan, nan, nan],
 [12, 13.0, 'IT', 'Products', '6', 'Navi', 'Mumbai', nan],
 [13, 14.0, 'Telecom', '3', 'Bangalore', nan, nan, nan],
 [14, 15.0, 'Infrastructure', '7', 'Chennai', nan, nan, nan],
 [15, 16.0, 'IT', '5', 'Chennai', nan, nan, nan],
 [16, 17.0, 'IT', '5', 'Chennai', nan, nan, nan],
 [17, 18.0, 'Infrastructure', '7', 'Coimbatore', nan, nan, nan],
 [18, 19.0, 'Telecom', '3', 'Chennai', nan, nan, nan],
 [19, 20.0, 'Telecom', '3', 'Bangalore', nan, nan, nan],
 [20, 21.0, 'Telecom', '3', 'Bengalore', nan, nan, nan],
 [21, 22.0, 'IT', '5', 'Chennai', nan, nan, nan]]

单位列表

df.values.ravel().tolist()

[0,
 1.0,
 'IT',
 '5',
 'New',
 'Delhi',
 nan,
 nan,
 1,
 2.0,
 'IT',
 '5',
 'Raipur',
 nan,
 nan,
 nan,
 2,
 3.0,
 'Infrastructure',
 '7',
 'Coimbatore',
 nan,
 nan,
 nan,
 3,
 4.0,
 'Telecom',
 '3',
 'Chennai',
 nan,
 nan,
 nan,
 4,
 5.0,
 'Telecom',
 '3',
 'Ahmedabad',
 nan,
 nan,
 nan,
 5,
 6.0,
 'IT',
 '5',
 'Chennai',
 nan,
 nan,
 nan,
 6,
 7.0,
 'IT',
 '5',
 'Chennai',
 nan,
 nan,
 nan,
 7,
 8.0,
 'IT',
 'Products',
 '6',
 'Bangalore',
 nan,
 nan,
 8,
 9.0,
 'IT',
 '5',
 'Chennai',
 nan,
 nan,
 nan,
 9,
 10.0,
 'IT',
 '5',
 'Chennai',
 nan,
 nan,
 nan,
 10,
 11.0,
 'Telecom',
 '3',
 'Bangalore',
 nan,
 nan,
 nan,
 11,
 12.0,
 'IT',
 '5',
 'Mysore',
 nan,
 nan,
 nan,
 12,
 13.0,
 'IT',
 'Products',
 '6',
 'Navi',
 'Mumbai',
 nan,
 13,
 14.0,
 'Telecom',
 '3',
 'Bangalore',
 nan,
 nan,
 nan,
 14,
 15.0,
 'Infrastructure',
 '7',
 'Chennai',
 nan,
 nan,
 nan,
 15,
 16.0,
 'IT',
 '5',
 'Chennai',
 nan,
 nan,
 nan,
 16,
 17.0,
 'IT',
 '5',
 'Chennai',
 nan,
 nan,
 nan,
 17,
 18.0,
 'Infrastructure',
 '7',
 'Coimbatore',
 nan,
 nan,
 nan,
 18,
 19.0,
 'Telecom',
 '3',
 'Chennai',
 nan,
 nan,
 nan,
 19,
 20.0,
 'Telecom',
 '3',
 'Bangalore',
 nan,
 nan,
 nan,
 20,
 21.0,
 'Telecom',
 '3',
 'Bengalore',
 nan,
 nan,
 nan,
 21,
 22.0,
 'IT',
 '5',
 'Chennai',
 nan,
 nan,
 nan]