回顾这些变换
太好了!您现在已经了解了数据透视表。在上一轮分析中,您遇到了一个具有非唯一 行索引/列 名组合的 DataFrame。为了透视该 DataFrame,您编写了代码先删除最后一行,然后再重塑。
在本练习中,您将改用数据透视表来修改代码,并与您使用 pivot 方法的做法进行比较。
已为您提供 fifa_players 数据集。
本练习是课程的一部分
使用 pandas 重塑数据
练习说明
- 丢弃
fifa_playersDataFrame 的第 5 行。 - 对
fifa_players使用.pivot(),按name建立索引,在列中以movement区分,获取所有评分。 - 使用数据透视表按
name和movement展示所有评分的均值,并将name设为索引。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Discard the fifth row to delete all repeated rows
fifa_drop = fifa_players.____(____)
# Use pivot method to get all scores by name and movement
fifa_pivot = fifa_drop.____(____)
# Print fifa_pivot
print(fifa_pivot)
# Use pivot table to get all scores by name and movement
fifa_pivot_table = fifa_players.____(index=____,
columns=____,
aggfunc=____)
# Print fifa_pivot_table
print(fifa_pivot_table)