- What will be output after following program execution?
import pandas as pd table = { "Name": ["anil", "vishal","manish","mohak"], "Age": [12,34,22,14], } df = pd.DataFrame(table) print(df) print (df.pivot_table(index="Name",columns="Name",values="Age"))
- Explain the following groupby() attributes with examples:
- size
- count
- Explain the agg() function on groupby object created using groupby() method?
- What is the use of transform() function? Explain with the help of example?
- A dataframe df1 stores data about passengers, flight and years as below:
- Compute total passenger per year
- Compute average passengers per month.
- For the given code fill in the blanks so that we get the desired output with sorting the dataframe first on Quantity and second on Cost.
import pandas as pd import numpy as np d = {'Product':['Apple','Pear','Banana','Grapes'], 'Quantity':[100,100,200,250], 'Cost':[1000,1500,1200,900]} df = pd.DataFrame(d) df1 = ______________________________________ print(df1) Product Quantity Cost 0 Apple 100 1000 1 Pear 100 1500 2 Banana 200 1200 3 Grapes 250 900
- Consider the following dataframes :
df1 df2 mark1 mark2 mark1 mark2 0 10 15 0 30 20 1 40 45 1 20 25 2 15 30 2 20 30 3 40 70 3 50 30
Write the commands to do the following operations on the dataframes given above :
- To rename column mark1 as Score1 in both the dataframes df1 and df2.
- To change index label of df1 from 0 to zero and from 1 to one.
- What is Pivoting? Name any two functions of Pandas which support pivoting.
- What is difference between pivot() and pivot_table() functions?
- What do you understand by reshaping of a data frame. Also, name the methods which are used to do so?
- How to Check if a Data Frame has any missing values ?
Year
|
Month
|
Passengers
|
|
0
1
2
3
4
|
2009
2009
2009
2009
2009
|
January
February
March
March
May
|
112
118
132
129
121
|
No comments:
Post a Comment