我的datafram2中有一行看起来像这样的行。很多行有2列。
player pos
Blake Bortles QB
Alvin Kamara RB
Dion Lewis RB
Keenan Allen WR
Michael Thomas WR
Tyrell Williams WR
Hunter Henry TE
Stephen Gostkowski K
Los Angeles Chargers D
Totals Team 1.0
Blake Bortles QB
Alvin Kamara RB
Dion Lewis RB
Keenan Allen WR
Michael Thomas WR
Tyrell Williams WR
Hunter Henry TE
Stephen Gostkowski K
Jacksonville Jaguars D
Totals Team 2.0
Blake Bortles QB
Todd Gurley RB
Alvin Kamara RB
Michael Thomas WR
Cooper Kupp WR
Tyrell Williams WR
Hunter Henry TE
Stephen Gostkowski K
Los Angeles Chargers D
我试图重塑它,所以每第11行开始一个新行,并且pos值是列名。所以我希望它看起来像这样:
QB RB RB WR WR WR TE K D team
Blake Bortles Alvin Kamara Dion Lewis Keenan Allen Michael Thomas Tyrell Williams Hunter Henry Stephen Gostkowski Los Angeles Chargers
Totals Team 1.0的最后一栏并不重要。但是,我希望第2排成为下一组球员。我试过重塑。
如果我放弃pos
列,我就设法做到了:
test = pd.DataFrame(rearrange.values.reshape(-1, 10),
columns=['QB','RB','RB','WR','WR','WR','TE','K','D','Team'])
但是如何使用pos
列进行操作?
有什么想法吗?
答案 0 :(得分:2)
如果IDocumentQuery
的顺序和值在每个组中相同,那么您似乎需要:
HasMoreResults