0

I'm looking for a way to delete specific lines (on a excel sheet) who dont contain list of numbers. I know the further exemple is not working, it's just to explain propely what i want to do

import pandas as pd

# Read Excel sheet
excel_sheet = pd.read_excel('sheet.xlsx', index_col=0)

# List of int that appears in a selected column that i want to keep (could be alone or surounded by other int or str
my_list = [123456, 1234567, 12345678]

# Delete method
excel_sheet.drop(excel_sheet[(excel_sheet['Column1'] != my_list)].index, inplace=True)```
Johntix
  • 1
  • 1

1 Answers1

0

Here is a reproducible example of a solution:

import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/practiceprobs/datasets/main/iris/iris.csv")

my_list = [5.1,4.9,4.7]

df[df['sepal_length'].isin(my_list) == False]
Claudio Paladini
  • 1,000
  • 1
  • 10
  • 20