need to create a matrix/pivot table in python
Question:
Answers:
filter and pivot
:
df1.query('Name1 == "A"').pivot('Name1', 'Name2', 'Marks2')
output:
Name2 B C D
Name1
A 10 20 6
NB. to remove the indexes names, add .rename_axis(index=None, columns=None)
.
filter and pivot
:
df1.query('Name1 == "A"').pivot('Name1', 'Name2', 'Marks2')
output:
Name2 B C D
Name1
A 10 20 6
NB. to remove the indexes names, add .rename_axis(index=None, columns=None)
.