2 回答
TA贡献1942条经验 获得超3个赞
您可以过滤掉第一个子列表并传递给 DataFrame 构造函数,也可以通过另一个列表设置列名称:
L = [[], ['1', 'Anthony Taylor', '6', '11.17', '0.68', '0.17', '1.83', '11', '0.17', '1'], ['2', 'Jonathan Moss', '4', '12.75', '0.73', '0.00', '2.00', '8', '0.00', '0'], ['3', 'Martin Atkinson', '3', '11.00', '0.69', '0.67', '1.67', '5', '0.00', '0'], ['4', 'Graham Scott', '3', '10.00', '0.67', '0.00', '0.33', '1', '0.00', '0'], ['5', 'Chris Kavanagh', '3', '10.33', '0.74', '0.00', '1.67', '5', '0.00', '0'], ['6', 'Michael Oliver', '2', '12.00', '0.62', '1.00', '2.00', '4', '0.00', '0'], ['7', 'Paul Tierney', '2', '12.50', '0.66', '0.00', '2.50', '5', '0.00', '0'], ['8', 'Mike Dean', '2', '14.50', '0.73', '0.50', '3.00', '6', '0.00', '0'], ['9', 'Andre Marriner', '2', '8.50', '0.53', '0.00', '2.00', '4', '0.00', '0'], ['10', 'Kevin Friend', '2', '9.50', '0.50', '0.00', '3.00', '6', '0.00', '0'], ['11', 'Craig Pawson', '1', '9.00', '0.45', '0.00', '1.00', '1', '0.00', '0'], ['12', 'Stuart Attwell', '1', '9.00', '0.75', '0.00', '2.00', '2', '0.00', '0'], ['13', 'Lee Probert', '1', '11.00', '0.73', '0.00', '0.00', '0', '0.00', '0'], ['', 'Total / Average', '32', '11.09', '0.66', '0.19', '1.81', '58', '0.03', '1']]
cols = ['id','name','a','b','c','d','e','f','g','h']
df = pd.DataFrame(L[1:], columns=cols)
print(df)
id name a b c d e f g h
0 1 Anthony Taylor 6 11.17 0.68 0.17 1.83 11 0.17 1
1 2 Jonathan Moss 4 12.75 0.73 0.00 2.00 8 0.00 0
2 3 Martin Atkinson 3 11.00 0.69 0.67 1.67 5 0.00 0
3 4 Graham Scott 3 10.00 0.67 0.00 0.33 1 0.00 0
4 5 Chris Kavanagh 3 10.33 0.74 0.00 1.67 5 0.00 0
5 6 Michael Oliver 2 12.00 0.62 1.00 2.00 4 0.00 0
6 7 Paul Tierney 2 12.50 0.66 0.00 2.50 5 0.00 0
7 8 Mike Dean 2 14.50 0.73 0.50 3.00 6 0.00 0
8 9 Andre Marriner 2 8.50 0.53 0.00 2.00 4 0.00 0
9 10 Kevin Friend 2 9.50 0.50 0.00 3.00 6 0.00 0
10 11 Craig Pawson 1 9.00 0.45 0.00 1.00 1 0.00 0
11 12 Stuart Attwell 1 9.00 0.75 0.00 2.00 2 0.00 0
12 13 Lee Probert 1 11.00 0.73 0.00 0.00 0 0.00 0
13 Total / Average 32 11.09 0.66 0.19 1.81 58 0.03 1
TA贡献1866条经验 获得超5个赞
使用pandas.DataFrame.from_records:
import pandas as pd
df = pd.DataFrame.from_records(x[1:]))
print(df)
输出:
0 1 2 3 4 5 6 7 8 9
0 1 Anthony Taylor 6 11.17 0.68 0.17 1.83 11 0.17 1
1 2 Jonathan Moss 4 12.75 0.73 0.00 2.00 8 0.00 0
2 3 Martin Atkinson 3 11.00 0.69 0.67 1.67 5 0.00 0
3 4 Graham Scott 3 10.00 0.67 0.00 0.33 1 0.00 0
4 5 Chris Kavanagh 3 10.33 0.74 0.00 1.67 5 0.00 0
5 6 Michael Oliver 2 12.00 0.62 1.00 2.00 4 0.00 0
6 7 Paul Tierney 2 12.50 0.66 0.00 2.50 5 0.00 0
7 8 Mike Dean 2 14.50 0.73 0.50 3.00 6 0.00 0
8 9 Andre Marriner 2 8.50 0.53 0.00 2.00 4 0.00 0
9 10 Kevin Friend 2 9.50 0.50 0.00 3.00 6 0.00 0
10 11 Craig Pawson 1 9.00 0.45 0.00 1.00 1 0.00 0
11 12 Stuart Attwell 1 9.00 0.75 0.00 2.00 2 0.00 0
12 13 Lee Probert 1 11.00 0.73 0.00 0.00 0 0.00 0
13 Total / Average 32 11.09 0.66 0.19 1.81 58 0.03 1
添加回答
举报