In this article we are going to discuss delete row columns pandas questions for ip class 12.

delete row columns pandas questions

Let’s start this article with objective type delete row columns pandas questions for class 12 informatics practices.

Short Answer Questions (1 Mark questions)

Take a look on this article before going through questions and answers.

MCQs

  1. Which of the following method is used to delete row/column from a dataframe?
    1. delete()
    2. remove()
    3. discard()
    4. drop()
  2. To delete a row from dataframe, which of the following method is correct? A dataframe is indexed with names.
    1. df.drop(df.row_index=’Jay’)
    2. df.drop(‘Jay’)
    3. df.drop(df.row=’Jay’)
    4. df.drop(df[‘Jay’])
  3. Which of the following method is correct for following dataframe to delete row by specifying index name? dt= ({‘Year1’:[1200,1220,1500]}, {‘Year2’:1800,1700,1400})
    df = pd.DataFrame(dt,index=[‘T1′,’T2’])
    Which of the following is correct to delete T2 index record from dataframe?
    1. df.drop(df.index[‘T2’])
    2. df.drop(df.idx=’T2′)
    3. df.drop(index=’T2′)
    4. df.drop(idx=’T2′)
  4. When you perform delete operation on dataframe, it returns a new dataframe always without changing the old dataframe. To avoid this which parameter you will use to change the original dataframe?
    1. intact = True
    2. inplace = True
    3. update = True
    4. replace = True
  5. Ankita is working on dataframe wihch has 4 rows and 3 columns. She wrote df.drop(df.index[[1,3]]). Which rows will be deleted from the dataframe?
    1. Row 1 and Row 3
    2. Rows between 1 and 3
    3. Row 2
    4. All rows from row no. 1 to index row no. 3
  6. Consider the datafame given in Que. No. 3. What happens when we add this statement df.Year1!=1200?
    1. It will delete all rows except 1200 value
    2. It will delete only row with 1200 value
    3. It will delete keep data with 1200 only
    4. None of these
  7. Which parameter is used to add in drop() method to delete columns?
    1. column = n (Where n is column number)
    2. col = n (Where n is column number)
    3. axis = 0
    4. axis = 1

Fill in the blanks:

  1. Mr. Subodh want to keep only three rows from top in his datframe by using a slice with dataframe. So he will write _________ to do the same.
  2. Ms. Nimisha want to ignore last three rows from dataframe by using a slice with dataframe. So she will wirte _______ to do the same.
  3. A dataframe has 4 columns named ID, Cname, PhoneNo and City. To delete PhoneNo and city column from the list using columnnames as parameter, ____________ statement will be used.
  4. To delete rows using list of index as a parameter, _________ statement will be used.
  5. To delete rows and columns together, __________________ statement will be used.

Answers:

MCQs:

  1. 4. drop()
  2. 2. df.drop(‘Jay’)
  3. 3. df.drop(index=’T2′)
  4. 2. inplace = True
  5. 1. Delete row 1 and row 3
  6. It will delete only row with 1200 value
  7. axis = 1

Fill in the blanks:

  1. df[:3]
  2. df[:-3]
  3. df.drop(columns=[‘PhonNo’,’City’])
  4. df.drop(df.index[[0,1]]) –> To delete rows 0 & 1
  5. df.drop(index=df.index[[1,2]],columns=df.columns[1,2])

Descriptive Questions:

OfficeQtr1Qtr2Qtr3
NorthRO800350450
WestHO500450600
SouthDO450550700
EastRO300200400
NorthHO450380100
EastHO500700550
  1. What are the ways to delete rows using drop() method?
    • To delete rows using drop() method do the following:
      • By index name or multiple indices
      • By index name with inplace
      • By .index attribute
      • != relational operator
  2. What are the ways to delete rows/columns without using drop() method?
    • del keyword
    • pop() function
    • loc/iloc
  3. What are the ways to delete columns using drop() method?
    • Using column labels
    • multiple columna names
    • passing columns parameter in drop()
    • column index list
  4. Consider above dataframe and write statement to
    1. Delete rows with labels East and West.
      • df=df.drop([‘East’,’West’])
      • df.drop([‘East’,’West’],inplace=True)
      • df=df.drop(df.index[[3,4]])
    2. Delete columns Office and Qtr3
      • df.drop([‘Office’,’Qtr3′],axis=1)
      • df.drop(columns=[‘Office’,’Qtr3′])
      • df.drop(df.coloumns[[0,3]],axis=1)
  5. Correct errors in the following statements:
    1. df.delete([‘north’,’south’])
      • df.drop([‘north’,’south’])
    2. df.drop(index.delete=”North”)
      • df.drop(df.index=’North’)
    3. df=df.drop([“North”,”South”],axis=1)
      • df=df.drop([‘North’,’South’],axis=0)
    4. df.drop(Qtr1,Qtr2)
      • df=df.drop([‘Qtr1′[‘Qtr2’],axis=1)
    5. df.drop(df.iloc[‘North’,’Qrt1′])
      • df=df.drop(df.iloc[0].name)
    6. df.drop(df.loc[0][‘Qtr4’])
      • df=df.drop(df.loc[:,[‘Qtr4’]],axis=1)
    7. df.drop(df.index[[‘North’,’West’]])
      • df=df.drop(df.index[[0,1]])
    8. df.drop(df!office[‘HO’])
      • print(df[df.office!=’HO’])

Just have look on the notes prepared for delete row columns pandas questions.

Delete rows and columns from DataDrame

I hope these questions will help you in preparing for your exams for dataframe delete and drop command. Thank you for reading this article delete row columns pandas questions.

Hit the like button and share this article delete row columns pandas questions with your friends. So learn more!

Feel free to ask any queries or doubts in the comment section.

Comment Your Views