The process of changing the structure of the DataFrame is known as reshaping. Which functions allow to do reshaping?
(A) pivot( )
(B) DataFrame_pivot( )
(C) PIVOT( )
(D) pivot_table( )
The process of changing the structure of the DataFrame is known as reshaping. Which functions allow to do reshaping?
(A) pivot( )
(B) DataFrame_pivot( )
(C) PIVOT( )
(D) pivot_table( )
Solution
In pandas, reshaping is done with pivot() and pivot_table(). pivot() reshapes data by turning unique values of one column into new columns, and it needs unique index-column pairs. pivot_table() does the same but can also aggregate duplicate entries, for example with sum or mean.
(B) and (C): DataFrame_pivot() does not exist in pandas, and PIVOT() is not a function either, because Python names are case-sensitive and the correct name is lowercase pivot().
pivot() fails with duplicate index-column pairs, so use pivot_table() when duplicates need aggregating.
Related questions:
2025: 13 May Shift 2
2025: 21 May Shift 1
2025: 27 May Shift 2
2026: 29 May Shift 1
2025: 3 June Shift 2