Pandas Assignment No3 Solution



Q. 1  Create 1-D Array from number 20 to 100 and perform the following operations: 


        A. Extract all odd numbers from array  
                (odd nos:All the numbers ending with 1,3,5,7 and 9 are odd numbers.) 
                (Desired Input: arr=[20, 21,22,23,.........100] 
                  Desired Output:  arr1=[21,23,,25,27.....]) 

  

        B. Replace all even numbers in array with -1 
            (Desired Input: arr=[20, 21,22,23,.........100] 
            Desired Output:  arr1=[-1,21,-1,23,-1.....]) 

         C. Convert this 1-D array to 2-D array  with 2 rows 
                (Desired Input: arr=[20, 21,22,23,.........100] 
                  Desired Output:  arr2=([21,22,23...], 
                                                [60,61,62....])) 



Q.2  Create a Dataframe as follows:  


       import pandas as pd 

  df=pd.DataFrame({'empno':[100,101,102,103,104,105],'name': ["A","B","C","D","E","F"],'salary': [10000,30000,12000,50000,40000,20000]}) 

   print(df) 

 

A. Print the total salary of all employees 
    (desired output: 162000) 
    

B. Write a Pandas program to display a summary of the basic information about a specified DataFrame and its data 
  


C. Find the details for emplyee whose salary is maximum 
(desired output: 3    103    D   50000) 
  
D. Write a Pandas program to count the number of rows and columns of a DataFrame 
(Desired output:  Total rows= 6 
    Total columns= 3) 

E. Create 'rank' column for displaying the rank as per salary 
(Desired output:   
   empno name  salary  rank 
0    100    A   10000   1.0 
1    101    B   30000   4.0 
2    102    C   12000   2.0 
3    103    D   50000   6.0 
4    104    E   40000   5.0 
5    105    F   20000   3.0  ) 


Solution













Post a Comment

0 Comments