- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python – Remove rows with Numbers
When it is required to remove rows with numbers, a list comprehension and the ‘not’ and ‘any’ operators are used.
Below is a demonstration of the same −
my_list = [[14, 'Pyt', 'fun'], ['Pyt', 'is', 'best'], [23, 51], ['Pyt', 'fun']] print("The list is :") print(my_list) my_result = [index for index in my_list if not any(isinstance(element, int) for element in index)] print("The result is :") print(my_result)
The list is : [[14, 'Pyt', 'fun'], ['Pyt', 'is', 'best'], [23, 51], ['Pyt', 'fun']] The result is : [['Pyt', 'is', 'best'], ['Pyt', 'fun']]
A list of list is defined and displayed on the console.
A list comprehension is used to iterate over the list, and each element is checked for belonging to integer type.
The element type is checked using ‘isinstance’ method.
If it is an integer, it is removed.
Otherwise, it is stored in a list, and assigned to a variable.
This is the output that is displayed on the console.
- Python - Remove positional rows
- Python program to remove rows with duplicate element in Matrix
- Remove similar element rows in tuple Matrix in Python
- Python – Remove Rows for similar Kth column element
- Python - Remove all characters except letters and numbers
- How to remove rows in a Pandas series with duplicate indices?
- MySQL query to remove numbers after hyphen in a VARCHAR string with numbers
- Python – Filter rows with required elements
- Python – Filter Rows with Range Elements
- Python – Rows with all List elements
- Python – Remove Dictionaries with Matching Values
- How to Humanize numbers with Python?
- Python – Extract rows with Even length strings
- Python – Rows with K string in Matrix
- Python – Extract rows with Complex data types