Q. A data frame fdf stores data about passengers, flights and years. First few rows of the data frame are shown below.
Year Month Passengers
0 2009 January 112
1 2009 February 118
2 2009 March 132
3 2009 April 129
4 2009 May 121
Using above data-frame, write commands for the following:
(a) Compute total passengers per year.
(b) Compute average passengers per month.
Answer :-
(a) fdf.pivot_table (index = 'year', values= 'passengers', aggfunc = 'sum')
(b) fdf.pivot_table (index = 'month', values= 'passengers', aggfunc = 'mean')
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )