Class 12 IP Practice Assignment Series 12
Class 12 IP Practice Assignment Series 12
Series-11
Revision Practice MCQ Unsolved Questions 17-09-2021
Class 12
Topic- Pandas dataframe pivoting
Subject IP
df-dataframe
name year item sales
ram 2015 tv 2
mohan 2015 tv 1
ram 2015 radio 4
mohan 2015 radio 5
ram 2016 tv 1
mohan 2016 tv 5
ram 2016 radio 3
mohan 2016 radio 5
import pandas as pd
import numpy as np
Q1. Which is a summarising technique to rearrange the columns and rows in a report so as to view data
from different angles?
a. Data pivoting
b. Data grouping
Q2. Which is used to show cross table format layout of our dataframe?
a. Sorting b. Pivoting
Q4. To create above dataframe df, so select correct python code for this:-
a.
df= pd.DataFrame(
{
‘name’ : [‘ram’, ‘mohan’, ‘ram’, ‘mohan’, ‘ram’, ‘mohan’, ‘ram’, ‘mohan’],
‘year’ : [2015, 2015, 2015, 2015, 2016, 2016, 2016, 2016 ],
‘item’ : [‘tv’, ‘tv’, ‘radio’, ‘radio’, ‘tv’, ‘tv’, ‘radio’, ‘radio’ ],
‘sales’ : [2, 1, 4, 5, 1, 5, 3, 5 ]
}
)
b.
df= pd.dataframe(
{
‘name’ : [‘ram’, ‘mohan’, ‘ram’, ‘mohan’, ‘ram’, ‘mohan’, ‘ram’, ‘mohan’],
‘year’ : [2015, 2015, 2015, 2015, 2016, 2016, 2016, 2016 ],
‘item’ : [‘tv’, ‘tv’, ‘radio’, ‘radio’, ‘tv’, ‘tv’, ‘radio’, ‘radio’ ],
‘sales’ : [2, 1, 4, 5, 1, 5, 3, 5 ]
}
Q5. To display year values in columns and To display name in rows with the help of pivot table.
To display sum all the sales values with the help of pivot table, so select python code for this:-
Year 2015 2016
name
mohan 6 10
ram 6 4
a.
print(df.pivot_table(index='name',columns='year',values='sales',aggfunc=np.max))
b.
print(df.pivot_table(index='name',columns='year',values='sales',aggfunc=np.sum))
Q6. To display year values in columns and To display name in rows with the help of pivot table.
To display maximum sales value with the help of pivot table, so select python code for this:-
Year 2015 2016
name
mohan 5 5
ram 4 3
a.
print(df.pivot_table(index='name',columns='year',values='sales',aggfunc=np.max))
b.
print(df.pivot_table(index='name',columns='year',values='sales',aggfunc=np.sum))
Q7. To display year values in columns and To display name in rows with the help of pivot table.
To display minimum sales value with the help of pivot table, so select python code for this:-
Year 2015 2016
Name
Mohan 1 5
Ram 2 1
a.
print(df.pivot_table(index='name',columns='year',values='sales',aggfunc=np.min))
b.
print(df.pivot_table(index='name',columns='year',values='sales',aggfunc=np.max))
Q8. To display year values in columns and To display name in rows with the help of pivot table.
To display average or mean sales value with the help of pivot table, so select python code for this:-
Year 2015 2016
name
mohan 3 5
ram 3 2
a.
print(df.pivot_table(index='name',columns='year',values='sales', aggfunc=np.mean))
b.
print(df.pivot_table(index='name',columns='year',values='sales', aggfunc=np.min))
Q9. To display names in columns and To display year values in rows with the help of pivot table.
To display sum sales value with the help of pivot table, so select python code for this:-
name mohan ram
Year
2015 6 10
2016 6 4
a.
print(df.pivot_table(index='year',columns='name',values='sales',aggfunc=np.max))
b.
print(df.pivot_table(index='year',columns='name',values='sales',aggfunc=np.sum))
Q10. To display names in columns and To display year values in rows with the help of pivot table.
To display max sales value with the help of pivot table, so select python code for this:-
name mohan ram
Year
2015 5 4
2016 5 3
a.
print(df.pivot_table(index='year',columns='name',values='sales',aggfunc=np.max))
b.
print(df.pivot_table(index='year',columns='name',values='sales',aggfunc=np.sum))
Q11. To display names in columns and To display year values in rows with the help of pivot table.
To display minimum sales value with the help of pivot table, so select python code for this:-
name mohan ram
Year
2015 1 2
2016 5 1
a.
print(df.pivot_table(index='year',columns='name',values='sales',aggfunc=np.min))
b.
print(df.pivot_table(index='year',columns='name',values='sales',aggfunc=np.max))
Q12. To display names in columns and To display year values in rows with the help of pivot table.
To display average/means sales value with the help of pivot table, so select python code for this:-
name mohan ram
Year
2015 1 2
2016 5 1
a.
print(df.pivot_table(index='year',columns='name',values='sales',aggfunc=np.mean))
b.
print(df.pivot_table(index='year',columns='name',values='sales',aggfunc=np.min))