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)``` 
1
  • 1
    excel_sheet = excel_sheet[excel_sheet['Column1'].isin(my_list)]? Commented Oct 20, 2022 at 9:14

1 Answer 1

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] 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.