CBSE Class 12 Informatics Practices
Question 139 of 167
Python Pandas — I — Question 29
Back to all questionsOriginal DataFrame
col1 col2 col3
0 1 6 9
1 4 7 0
2 3 8 1
New DataFrame :
col1 col2 col3
0 1 6 9
The code creates a DataFrame using the pandas library in Python, named df, with three columns ('col1', 'col2', 'col3') and three rows of data. The DataFrame df is printed, and then a new DataFrame named dfn is created by dropping the rows with indices 1 and 2 from the original DataFrame using df.drop(df.index[[1, 2]]). The resulting DataFrame, dfn, contains only the first row from the df DataFrame, removing rows 2 and 3.