Skip to content
Advertisement

Pandas Selection of rows not working propelry

I am trying to delete rows of a df which are not part of an other columns entry from another table. For further explanation: I have a table with transactions including materialnumbers and another table with production information also including materialnumbers. I want to delete every row where a materialnumber is contained which is not in the other table.

My full code is not working. Tho the code is doing what I expect when used on a small sample. See below.

JavaScript

Works as predicted

JavaScript

both files new_L aswell as L contain the same values though in the head() part some rows get removed.

The Tables can be seen as following:

JavaScript

Many Thanks in advance

Advertisement

Answer

You probably want to be using the merge function in pandas opposed to isin.

The code below is a simple demonstration of how to use the function

We use how='left' so that only ‘materials’ that are in the left dataframe are included. The on='MAT' is used to tell pandas to look at this column to decide what should be merged.

JavaScript

This produces the output shown below.

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement