Data Frame Qp_1

10 Questions | Total Attempts: 1252

SettingsSettingsSettings
Please wait...
Data Frame Qp_1

.


Questions and Answers
  • 1. 
    What will be the output of the following code? import pandas as pd import numpy as np arr1=np.array([[1,2,3],[4,5,6]]) df=pd.DataFrame(arr1,columns=['num1','num2','num3']) print(df.iloc[0,2])
  • 2. 
    A dictionary grade contains the following Grade={'Name':['Rashmi','Harsh','Ganesh','Priya','Vivek'],'Grade':['A1','A2','B1','A1','B2']} Write the statement to create a data frame called "Gr"
  • 3. 
    A dictionary grade contains the following Grade={'Name':['Rashmi','Harsh','Ganesh','Priya','Vivek'],'Grade':['A1','A2','B1','A1','B2']} Write the statement to add a column called 'Marks' with the following data. [97,92,95,89,96] use only single quotes in the answer as the software gives correct only for exact match
  • 4. 
    Delete 3rd and 5th rows Hint use drop method in a single statement
  • 5. 
    Give the output import pandas as pd d={'one':pd.Series([1.,2.,3.],index=['a','b','c']),   'two':pd.Series([1.,2.,3.,4.],index=['a','b','c','d'])} df=pd.DataFrame(d) print(df) Hint.  only one space between columns and rows and start from the left and  and leave one space from top margin
  • 6. 
    Give the output import pandas as pd d={'one':pd.Series([1.,2.,3.],index=['a','b','c']),   'two':pd.Series([1.,2.,3.,4.],index=['a','b','c','d'])} df1=pd.DataFrame(d,index=['d','b','a']) print(df1) Hint.  only one space between columns and rows and start from the left and top margin
  • 7. 
      import pandas as pd d={'one':pd.Series([1.,2.,3.],index=['a','b','c']),   'two':pd.Series([1.,2.,3.,4.],index=['a','b','c','d'])} df2=pd.DataFrame(d,index=['d','a'],columns=['two','three']) print(df2)
  • 8. 
    Import pandas as pd d={'one':pd.Series([1.,2.,3.],index=['a','b','c']),    'two':pd.Series([1.,2.,3.,4.],index=['a','b','c','d'])} df=pd.DataFrame(d) df1=pd.DataFrame(d,index=['d','b','a']) df2=pd.DataFrame(d,index=['d','a'],columns=['two','three']) Write code to  Display only column 'one' from dataframes df and df1, column 'two' from  df2. Hint: Write print statements one below the other
  • 9. 
    Import pandas as pd d={'one':pd.Series([1.,2.,3.],index=['a','b','c']),    'two':pd.Series([1.,2.,3.,4.],index=['a','b','c','d'])} df=pd.DataFrame(d) df1=pd.DataFrame(d,index=['d','b','a']) df2=pd.DataFrame(d,index=['d','a'],columns=['two','three']) Write code to display only rows 0 and 1 from dataframes df, df1  and df2 Hint :use iloc use print statements one below the other  
  • 10. 
    Import pandas as pd d={'one':pd.Series([1.,2.,3.],index=['a','b','c']),    'two':pd.Series([1.,2.,3.,4.],index=['a','b','c','d'])} df=pd.DataFrame(d) df1=pd.DataFrame(d,index=['d','b','a']) df2=pd.DataFrame(d,index=['d','a'],columns=['two','three']) Write code to display only column one for rows b and c from df 
Back to Top Back to top