Skip to content
Advertisement

Drop data frames with condition contains (os.path.exists)

Trying to drop rows with path that doesn’t exist…

JavaScript

Error:

JavaScript

Advertisement

Answer

As it stands, os.path.exists looks at the whole str representation of the column, not element-by-element. One way is to apply:

JavaScript

If you print exists, it will be a boolean series saying which paths exist and which do not.

JavaScript

inverted exist to drop the one with false result, now it will drop the files that doesn’t exist.

Advertisement